[llvm-commits] [PATCH] Use template to distinguish between variants of function

Samuel Tardieu sam at rfc1149.net
Tue Oct 7 08:30:53 PDT 2008


GCC 4.4.0 gives an error on the "int" declaration for example
saying that it has already been declared (using the "short"
one). Using templates here allow the compiler to distinguish
between the function to choose and is, IMO, cleaner.

Also, "llvm/Support/DataTypes.h" was not included, leading to
error messages about not knowing "uint32_t" for example.
---
 lib/Target/CellSPU/SPU.h |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/lib/Target/CellSPU/SPU.h b/lib/Target/CellSPU/SPU.h
index 2d765b6..776b9bf 100644
--- a/lib/Target/CellSPU/SPU.h
+++ b/lib/Target/CellSPU/SPU.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_TARGET_IBMCELLSPU_H
 #define LLVM_TARGET_IBMCELLSPU_H
 
+#include "llvm/Support/DataTypes.h"
 #include <iosfwd>
 
 namespace llvm {
@@ -33,25 +34,33 @@ namespace llvm {
     This predicate tests for a signed 10-bit value, returning the 10-bit value
     as a short if true.
    */
-  inline bool isS10Constant(short Value) {
+  template<typename T>
+  inline bool isS10Constant(T Value);
+
+  template<>
+  inline bool isS10Constant<short>(short Value) {
     int SExtValue = ((int) Value << (32 - 10)) >> (32 - 10);
     return ((Value > 0 && Value <= (1 << 9) - 1)
             || (Value < 0 && (short) SExtValue == Value));
   }
 
-  inline bool isS10Constant(int Value) {
+  template<>
+  inline bool isS10Constant<int>(int Value) {
     return (Value >= -(1 << 9) && Value <= (1 << 9) - 1);
   }
 
-  inline bool isS10Constant(uint32_t Value) {
+  template<>
+  inline bool isS10Constant<uint32_t>(uint32_t Value) {
     return (Value <= ((1 << 9) - 1));
   }
 
-  inline bool isS10Constant(int64_t Value) {
+  template<>
+  inline bool isS10Constant<int64_t>(int64_t Value) {
     return (Value >= -(1 << 9) && Value <= (1 << 9) - 1);
   }
 
-  inline bool isS10Constant(uint64_t Value) {
+  template<>
+  inline bool isS10Constant<uint64_t>(uint64_t Value) {
     return (Value <= ((1 << 9) - 1));
   }
 




More information about the llvm-commits mailing list