[llvm-commits] [PATCH] Add declaration of hash_value in APFloat / APInt (required for xlC on AIX)
Kai
kai at redstar.de
Tue Oct 30 03:50:45 PDT 2012
Hi!
Based on the discussion I added a comment to the required declaration. I
also found other places where changes are necessary. Here are my patches:
xlc_decl.diff: Adds the declaration of hash_value to prevent compile
error with xlC
xlc_tblgen.diff: Adds parenthesis around an expression to prevent
compile error with xlC
xlc_alignof.diff: Adds support for LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
xlc_atomics.diff: xlC 12.1 supports the same intrinsic functions like gcc.
Please note that these changes are not enough to compile everything with
xlC. I work on more patches. BTW I am using xlC 12.1 with latest PTF
applied.
Please review and commit if it looks good.
Regards
Kai
On 27.10.2012 21:29, Kai wrote:
> Hi!
>
> I am trying to compile LLVM with the IBM xlC compiler on AIX 7.1 The
> first issue I encounter is that the function hash_value() is declared as
> a friend of APFloat and APInt, but no matching declaration is provided.
> This results in the error message:
>
> "../llvm-git/lib/Support/APFloat.cpp", line 2731.11: 1540-0432 (S) The
> qualified declarator "llvm::hash_value" must refer to an existing
> declaration.
>
> The draft standard says in section 7.3.1.2 "Namespace member definitions":
>
> "... If a friend declaration in a non-local class first declares a class
> or function95 the friend class or function is a member of the innermost
> enclosing namespace. The name of the friend is not found by unqualified
> lookup (3.4.1) or by qualified lookup (3.4.3) until a matching
> declaration is provided in that namespace scope (either before or after
> the class definition granting friendship). ..."
>
> I conclude that the declaration is required for conformance with the C++
> standard. The attached patch resolves the problem.
>
> Please review and commit if it looks good.
>
> Regards
> Kai
>
>
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
diff --git a/include/llvm/Support/AlignOf.h b/include/llvm/Support/AlignOf.h
index 22c07d0..d6b0ab8 100644
--- a/include/llvm/Support/AlignOf.h
+++ b/include/llvm/Support/AlignOf.h
@@ -78,7 +78,7 @@ template <size_t Alignment> struct AlignedCharArrayImpl;
template <> struct AlignedCharArrayImpl<x> { \
char alignas(x) aligned; \
}
-#elif defined(__GNUC__)
+#elif defined(__GNUC__) || defined(__IBM_ATTRIBUTES)
#define LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(x) \
template <> struct AlignedCharArrayImpl<x> { \
char aligned __attribute__((aligned(x))); \
-------------- next part --------------
diff --git a/lib/Support/Atomic.cpp b/lib/Support/Atomic.cpp
index 3001f6c..8e65198 100644
--- a/lib/Support/Atomic.cpp
+++ b/lib/Support/Atomic.cpp
@@ -25,7 +25,7 @@ void sys::MemoryFence() {
#if LLVM_HAS_ATOMICS == 0
return;
#else
-# if defined(__GNUC__)
+# if defined(__GNUC__) || (defined(__IBMCPP__) && __IBMCPP__ >= 1210)
__sync_synchronize();
# elif defined(_MSC_VER)
MemoryBarrier();
@@ -43,7 +43,7 @@ sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr,
if (result == old_value)
*ptr = new_value;
return result;
-#elif defined(__GNUC__)
+#elif defined(__GNUC__) || (defined(__IBMCPP__) && __IBMCPP__ >= 1210)
return __sync_val_compare_and_swap(ptr, old_value, new_value);
#elif defined(_MSC_VER)
return InterlockedCompareExchange(ptr, new_value, old_value);
@@ -56,7 +56,7 @@ sys::cas_flag sys::AtomicIncrement(volatile sys::cas_flag* ptr) {
#if LLVM_HAS_ATOMICS == 0
++(*ptr);
return *ptr;
-#elif defined(__GNUC__)
+#elif defined(__GNUC__) || (defined(__IBMCPP__) && __IBMCPP__ >= 1210)
return __sync_add_and_fetch(ptr, 1);
#elif defined(_MSC_VER)
return InterlockedIncrement(ptr);
@@ -69,7 +69,7 @@ sys::cas_flag sys::AtomicDecrement(volatile sys::cas_flag* ptr) {
#if LLVM_HAS_ATOMICS == 0
--(*ptr);
return *ptr;
-#elif defined(__GNUC__)
+#elif defined(__GNUC__) || (defined(__IBMCPP__) && __IBMCPP__ >= 1210)
return __sync_sub_and_fetch(ptr, 1);
#elif defined(_MSC_VER)
return InterlockedDecrement(ptr);
@@ -82,7 +82,7 @@ sys::cas_flag sys::AtomicAdd(volatile sys::cas_flag* ptr, sys::cas_flag val) {
#if LLVM_HAS_ATOMICS == 0
*ptr += val;
return *ptr;
-#elif defined(__GNUC__)
+#elif defined(__GNUC__) || (defined(__IBMCPP__) && __IBMCPP__ >= 1210)
return __sync_add_and_fetch(ptr, val);
#elif defined(_MSC_VER)
return InterlockedExchangeAdd(ptr, val) + val;
-------------- next part --------------
diff --git a/include/llvm/ADT/APFloat.h b/include/llvm/ADT/APFloat.h
index 5a625a4..7710d6d 100644
--- a/include/llvm/ADT/APFloat.h
+++ b/include/llvm/ADT/APFloat.h
@@ -463,6 +463,10 @@ namespace llvm {
exponent_t exponent2 : 11;
unsigned int sign2: 1;
};
+
+ // See friend declaration above. This additional declaration is required in
+ // order to compile LLVM with IBM xlC compiler.
+ hash_code hash_value(const APFloat &Arg);
} /* namespace llvm */
#endif /* LLVM_FLOAT_H */
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index 90114e2..c7c8016 100644
--- a/include/llvm/ADT/APInt.h
+++ b/include/llvm/ADT/APInt.h
@@ -1780,6 +1780,9 @@ inline APInt Not(const APInt& APIVal) {
} // End of APIntOps namespace
+ // See friend declaration above. This additional declaration is required in
+ // order to compile LLVM with IBM xlC compiler.
+ hash_code hash_value(const APInt &Arg);
} // End of llvm namespace
#endif
diff --git a/include/llvm/CodeGen/MachineOperand.h b/include/llvm/CodeGen/MachineOperand.h
index 5a18210..606833c 100644
--- a/include/llvm/CodeGen/MachineOperand.h
+++ b/include/llvm/CodeGen/MachineOperand.h
@@ -687,6 +687,9 @@ inline raw_ostream &operator<<(raw_ostream &OS, const MachineOperand& MO) {
return OS;
}
+ // See friend declaration above. This additional declaration is required in
+ // order to compile LLVM with IBM xlC compiler.
+ hash_code hash_value(const MachineOperand &MO);
} // End llvm namespace
#endif
-------------- next part --------------
diff --git a/utils/TableGen/CodeGenSchedule.cpp b/utils/TableGen/CodeGenSchedule.cpp
index a8c9392..63cc97a 100644
--- a/utils/TableGen/CodeGenSchedule.cpp
+++ b/utils/TableGen/CodeGenSchedule.cpp
@@ -1591,7 +1591,7 @@ unsigned CodeGenProcModel::getProcResourceIdx(Record *PRDef) const {
PrintFatalError(PRDef->getLoc(), "ProcResource def is not included in "
"the ProcResources list for " + ModelName);
// Idx=0 is reserved for invalid.
- return 1 + PRPos - ProcResourceDefs.begin();
+ return 1 + (PRPos - ProcResourceDefs.begin());
}
#ifndef NDEBUG
diff --git a/utils/TableGen/SubtargetEmitter.cpp b/utils/TableGen/SubtargetEmitter.cpp
index 806bda1..f1a06bb 100644
--- a/utils/TableGen/SubtargetEmitter.cpp
+++ b/utils/TableGen/SubtargetEmitter.cpp
@@ -1053,7 +1053,7 @@ void SubtargetEmitter::EmitSchedClassTables(SchedClassTables &SchedTables,
continue;
std::vector<MCSchedClassDesc> &SCTab =
- SchedTables.ProcSchedClasses[1 + PI - SchedModels.procModelBegin()];
+ SchedTables.ProcSchedClasses[1 + (PI - SchedModels.procModelBegin())];
OS << "\n// {Name, NumMicroOps, BeginGroup, EndGroup,"
<< " WriteProcResIdx,#, WriteLatencyIdx,#, ReadAdvanceIdx,#}\n";
More information about the llvm-commits
mailing list