[llvm] r174271 - [Support] Add LLVM_IS_UNALIGNED_ACCESS_FAST.
Michael J. Spencer
bigcheesegs at gmail.com
Sun Feb 3 02:48:31 PST 2013
Author: mspencer
Date: Sun Feb 3 04:48:31 2013
New Revision: 174271
URL: http://llvm.org/viewvc/llvm-project?rev=174271&view=rev
Log:
[Support] Add LLVM_IS_UNALIGNED_ACCESS_FAST.
Modified:
llvm/trunk/include/llvm/Support/Compiler.h
llvm/trunk/lib/Object/ELFObjectFile.cpp
Modified: llvm/trunk/include/llvm/Support/Compiler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=174271&r1=174270&r2=174271&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Compiler.h (original)
+++ llvm/trunk/include/llvm/Support/Compiler.h Sun Feb 3 04:48:31 2013
@@ -311,4 +311,17 @@
# define LLVM_MEMORY_SANITIZER_BUILD 0
#endif
+/// \macro LLVM_IS_UNALIGNED_ACCESS_FAST
+/// \brief Is unaligned memory access fast on the host machine.
+///
+/// Don't specialize on alignment for platforms where unaligned memory accesses
+/// generates the same code as aligned memory accesses for common types.
+#if defined(_M_AMD64) || defined(_M_IX86) || defined(__amd64) || \
+ defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || \
+ defined(_X86_) || defined(__i386) || defined(__i386__)
+# define LLVM_IS_UNALIGNED_ACCESS_FAST 1
+#else
+# define LLVM_IS_UNALIGNED_ACCESS_FAST 0
+#endif
+
#endif
Modified: llvm/trunk/lib/Object/ELFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFObjectFile.cpp?rev=174271&r1=174270&r2=174271&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ELFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ELFObjectFile.cpp Sun Feb 3 04:48:31 2013
@@ -27,30 +27,42 @@ ObjectFile *ObjectFile::createELFObjectF
1ULL << CountTrailingZeros_64(uintptr_t(Object->getBufferStart()));
if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB)
+#if !LLVM_IS_UNALIGNED_ACCESS_FAST
if (MaxAlignment >= 4)
return new ELFObjectFile<ELFType<support::little, 4, false> >(Object, ec);
- else if (MaxAlignment >= 2)
+ else
+#endif
+ if (MaxAlignment >= 2)
return new ELFObjectFile<ELFType<support::little, 2, false> >(Object, ec);
else
llvm_unreachable("Invalid alignment for ELF file!");
else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB)
+#if !LLVM_IS_UNALIGNED_ACCESS_FAST
if (MaxAlignment >= 4)
return new ELFObjectFile<ELFType<support::big, 4, false> >(Object, ec);
- else if (MaxAlignment >= 2)
+ else
+#endif
+ if (MaxAlignment >= 2)
return new ELFObjectFile<ELFType<support::big, 2, false> >(Object, ec);
else
llvm_unreachable("Invalid alignment for ELF file!");
else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB)
+#if !LLVM_IS_UNALIGNED_ACCESS_FAST
if (MaxAlignment >= 8)
return new ELFObjectFile<ELFType<support::big, 8, true> >(Object, ec);
- else if (MaxAlignment >= 2)
+ else
+#endif
+ if (MaxAlignment >= 2)
return new ELFObjectFile<ELFType<support::big, 2, true> >(Object, ec);
else
llvm_unreachable("Invalid alignment for ELF file!");
else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) {
+#if !LLVM_IS_UNALIGNED_ACCESS_FAST
if (MaxAlignment >= 8)
return new ELFObjectFile<ELFType<support::little, 8, true> >(Object, ec);
- else if (MaxAlignment >= 2)
+ else
+#endif
+ if (MaxAlignment >= 2)
return new ELFObjectFile<ELFType<support::little, 2, true> >(Object, ec);
else
llvm_unreachable("Invalid alignment for ELF file!");
More information about the llvm-commits
mailing list