VS2005 patches

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

VS2005 patches

Morten Ofstad
In the VS2005 debug std libraries, the lower_bound algorithm uses a
function known as _DEBUG_LT. The problem with this is that it asserts
that if a < b then !(b < a). It also asserts that the input is actually
sorted by using < to compare the elements.

In LLVM there are a couple of places where the lower_bound algorithm is
used with a lower bound of a different type than the iterators. It seems
to me upon checking the relevant parts of the ISO C++ standard (25.3 Sorting
and related operations) that MS are within their rights to make these
requirements on the < operator, although it's pretty annoying.

There are three possible solutions (in order of preference):

1) when the problem occurs because implicit conversion fails when the
     operator< is a class member and you switch the arguments, make an
     explicit conversion of the lower bound value.
2) to provide another operator< that provides the necessary comparision
     for _DEBUG_LT to work
3) change code that looks for a lower bound of a different type to look
     for a lower bound of the same type as the iterators

I used 1) in CorrelatedExprs
I used 2) in LiveInterval, X86FloatingPoint
I used 3) in SubTargetFeature

-

In addition to this, I include a patch to the X86JITInfo so it will compile with the X64 platform and patches to the
current project files to build the X86GenSubTarget.inc file with TableGen.


Index: lib/Target/X86/X86JITInfo.cpp
===================================================================
RCS file: /var/cvs/llvm/llvm/lib/Target/X86/X86JITInfo.cpp,v
retrieving revision 1.14
diff -u -r1.14 X86JITInfo.cpp
--- lib/Target/X86/X86JITInfo.cpp 22 Jul 2005 20:49:37 -0000 1.14
+++ lib/Target/X86/X86JITInfo.cpp 26 Jan 2006 14:40:04 -0000
@@ -18,6 +18,9 @@
 #include "llvm/Config/alloca.h"
 #include <cstdlib>
 #include <iostream>
+#ifdef _MSC_VER
+#include <intrin.h>
+#endif
 using namespace llvm;
 
 void X86JITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
@@ -64,9 +67,6 @@
     "popl    %ebp\n"
     "ret\n");
 #else
-  extern "C" void *_AddressOfReturnAddress(void);
-  #pragma intrinsic(_AddressOfReturnAddress)
-
   void X86CompilationCallback2(void);
 
   _declspec(naked) void X86CompilationCallback(void) {


Index: include/llvm/CodeGen/LiveInterval.h
===================================================================
RCS file: /var/cvs/llvm/llvm/include/llvm/CodeGen/LiveInterval.h,v
retrieving revision 1.15
diff -u -r1.15 LiveInterval.h
--- include/llvm/CodeGen/LiveInterval.h 20 Oct 2005 07:37:59 -0000 1.15
+++ include/llvm/CodeGen/LiveInterval.h 26 Jan 2006 13:22:01 -0000
@@ -64,6 +64,9 @@
     return V < LR.start;
   }
 
+  inline bool operator<(const LiveRange &LR, unsigned V) {
+    return LR.start < V;
+  }
 
   /// LiveInterval - This class represents some number of live ranges for a
   /// register or value.  This class also contains a bit of register allocator
Index: include/llvm/Target/SubtargetFeature.h
===================================================================
RCS file: /var/cvs/llvm/llvm/include/llvm/Target/SubtargetFeature.h,v
retrieving revision 1.5
diff -u -r1.5 SubtargetFeature.h
--- include/llvm/Target/SubtargetFeature.h 25 Oct 2005 15:15:28 -0000 1.5
+++ include/llvm/Target/SubtargetFeature.h 26 Jan 2006 13:05:04 -0000
@@ -36,8 +36,8 @@
   uint32_t Value;                       // K-V integer value
   
   // Compare routine for std binary search
-  bool operator<(const std::string &S) const {
-    return strcmp(Key, S.c_str()) < 0;
+  bool operator<(const SubtargetFeatureKV &S) const {
+    return strcmp(Key, S.Key) < 0;
   }
 };
   
@@ -51,8 +51,8 @@
   void *Value;                          // K-V pointer value
   
   // Compare routine for std binary search
-  bool operator<(const std::string &S) const {
-    return strcmp(Key, S.c_str()) < 0;
+  bool operator<(const SubtargetInfoKV &S) const {
+    return strcmp(Key, S.Key) < 0;
   }
 };
   
Index: lib/Target/SubtargetFeature.cpp
===================================================================
RCS file: /var/cvs/llvm/llvm/lib/Target/SubtargetFeature.cpp,v
retrieving revision 1.8
diff -u -r1.8 SubtargetFeature.cpp
--- lib/Target/SubtargetFeature.cpp 25 Oct 2005 15:15:28 -0000 1.8
+++ lib/Target/SubtargetFeature.cpp 26 Jan 2006 13:07:14 -0000
@@ -112,10 +112,13 @@
 
 /// Find KV in array using binary search.
 template<typename T> const T *Find(const std::string &S, const T *A, size_t L) {
+  // Make the lower bound element we're looking for
+  T KV;
+  KV.Key = S.c_str();
   // Determine the end of the array
   const T *Hi = A + L;
   // Binary search the array
-  const T *F = std::lower_bound(A, Hi, S);
+  const T *F = std::lower_bound(A, Hi, KV);
   // If not found then return NULL
   if (F == Hi || std::string(F->Key) != S) return NULL;
   // Return the found array item
Index: lib/Target/X86/X86FloatingPoint.cpp
===================================================================
RCS file: /var/cvs/llvm/llvm/lib/Target/X86/X86FloatingPoint.cpp,v
retrieving revision 1.48
diff -u -r1.48 X86FloatingPoint.cpp
--- lib/Target/X86/X86FloatingPoint.cpp 22 Jan 2006 23:37:17 -0000 1.48
+++ lib/Target/X86/X86FloatingPoint.cpp 26 Jan 2006 13:36:27 -0000
@@ -281,7 +281,8 @@
     unsigned from;
     unsigned to;
     bool operator<(const TableEntry &TE) const { return from < TE.from; }
-    bool operator<(unsigned V) const { return from < V; }
+    friend bool operator<(const TableEntry &TE, unsigned V) { return TE.from < V; }
+    friend bool operator<(unsigned V, const TableEntry &TE) { return V < TE.from; }
   };
 }
 
Index: lib/Transforms/Scalar/CorrelatedExprs.cpp
===================================================================
RCS file: /var/cvs/llvm/llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp,v
retrieving revision 1.31
diff -u -r1.31 CorrelatedExprs.cpp
--- lib/Transforms/Scalar/CorrelatedExprs.cpp 22 Jan 2006 23:32:06 -0000 1.31
+++ lib/Transforms/Scalar/CorrelatedExprs.cpp 26 Jan 2006 10:34:55 -0000
@@ -135,7 +135,7 @@
     Relation &getRelation(Value *V) {
       // Binary search for V's entry...
       std::vector<Relation>::iterator I =
-        std::lower_bound(Relationships.begin(), Relationships.end(), V);
+        std::lower_bound(Relationships.begin(), Relationships.end(), Relation(V));
 
       // If we found the entry, return it...
       if (I != Relationships.end() && I->getValue() == V)
@@ -148,7 +148,7 @@
     const Relation *requestRelation(Value *V) const {
       // Binary search for V's entry...
       std::vector<Relation>::const_iterator I =
-        std::lower_bound(Relationships.begin(), Relationships.end(), V);
+        std::lower_bound(Relationships.begin(), Relationships.end(), Relation(V));
       if (I != Relationships.end() && I->getValue() == V)
         return &*I;
       return 0;


Index: win32/X86/x86.vcproj
===================================================================
RCS file: /var/cvs/llvm/llvm/win32/x86/x86.vcproj,v
retrieving revision 1.17
diff -u -r1.17 x86.vcproj
--- win32/X86/x86.vcproj 17 Dec 2005 00:14:47 -0000 1.17
+++ win32/X86/x86.vcproj 26 Jan 2006 15:09:36 -0000
@@ -123,7 +123,9 @@
 ..\$(IntDir)\TableGen.exe -gen-instr-desc -I ..\..\lib\Target\X86 $(InputPath) -o X86GenInstrInfo.inc
 ..\$(IntDir)\TableGen.exe -gen-asm-writer -I ..\..\lib\Target\X86 $(InputPath) -o X86GenAsmWriter.inc
 ..\$(IntDir)\TableGen.exe -gen-asm-writer -asmwriternum=1 -I ..\..\lib\Target\X86 $(InputPath) -o X86GenAsmWriter1.inc
-..\$(IntDir)\TableGen.exe -gen-dag-isel -I ..\..\lib\Target\X86 $(InputPath) -o X86GenDAGISel.inc"
+..\$(IntDir)\TableGen.exe -gen-dag-isel -I ..\..\lib\Target\X86 $(InputPath) -o X86GenDAGISel.inc
+..\$(IntDir)\TableGen.exe -gen-subtarget -I ..\..\lib\Target\X86 $(InputPath) -o X86GenSubtarget.inc
+"
  AdditionalDependencies="$(InputDir)X86InstrInfo.td;$(InputDir)X86RegisterInfo.td;$(InputDir)..\Target.td;$(ProjectDir)..\$(IntDir)\TableGen.exe"
  Outputs="X86GenRegisterNames.inc;X86GenRegisterInfo.h.inc;X86GenRegisterInfo.inc;X86GenInstrNames.inc;X86GenInstrInfo.inc;X86GenAsmWriter.inc;X86GenAsmWriter1.inc;X86GenDAGISel.inc"/>
  </FileConfiguration>
@@ -139,7 +141,8 @@
 ..\$(IntDir)\TableGen.exe -gen-instr-desc -I ..\..\lib\Target\X86 $(InputPath) -o X86GenInstrInfo.inc
 ..\$(IntDir)\TableGen.exe -gen-asm-writer -I ..\..\lib\Target\X86 $(InputPath) -o X86GenAsmWriter.inc
 ..\$(IntDir)\TableGen.exe -gen-asm-writer -asmwriternum=1 -I ..\..\lib\Target\X86 $(InputPath) -o X86GenAsmWriter1.inc
-..\$(IntDir)\TableGen.exe -gen-dag-isel -I ..\..\lib\Target\X86 $(InputPath) -o X86GenDAGISel.inc"
+..\$(IntDir)\TableGen.exe -gen-dag-isel -I ..\..\lib\Target\X86 $(InputPath) -o X86GenDAGISel.inc
+"
  AdditionalDependencies="$(InputDir)X86InstrInfo.td;$(InputDir)X86RegisterInfo.td;$(InputDir)..\Target.td;$(ProjectDir)..\$(IntDir)\TableGen.exe"
  Outputs="X86GenRegisterNames.inc;X86GenRegisterInfo.h.inc;X86GenRegisterInfo.inc;X86GenInstrNames.inc;X86GenInstrInfo.inc;X86GenAsmWriter.inc;X86GenAsmWriter1.inc;X86GenDAGISel.inc"/>
  </FileConfiguration>
@@ -261,6 +264,9 @@
  <File
  RelativePath=".\X86GenRegisterNames.inc">
  </File>
+ <File
+ RelativePath=".\X86GenSubtarget.inc">
+ </File>
  </Filter>
  </Files>
  <Globals>

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev