[llvm] 3194928 - [llvm-exegesis] Refactor MMAP platform-specific preprocessor directives (#75422)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 14 12:07:50 PST 2023
Author: Aiden Grossman
Date: 2023-12-14T12:07:46-08:00
New Revision: 3194928c3cfa6623c5de78ae7ab2ab7ab0cf0232
URL: https://github.com/llvm/llvm-project/commit/3194928c3cfa6623c5de78ae7ab2ab7ab0cf0232
DIFF: https://github.com/llvm/llvm-project/commit/3194928c3cfa6623c5de78ae7ab2ab7ab0cf0232.diff
LOG: [llvm-exegesis] Refactor MMAP platform-specific preprocessor directives (#75422)
This patch refactors the MMAP platform-specific preprocessor directives
in llvm-exegesis to a single file instead of having duplicate code split
across multiple files. These originally got introduced to get buildbots
green again due to platform specific failures.
Added:
llvm/tools/llvm-exegesis/lib/MmapUtils.h
Modified:
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/X86/Target.cpp
llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 7bb0218ed53386..41960c23a10d19 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -13,6 +13,7 @@
#include "BenchmarkRunner.h"
#include "Error.h"
#include "MCInstrDescView.h"
+#include "MmapUtils.h"
#include "PerfHelper.h"
#include "SubprocessMemory.h"
#include "Target.h"
@@ -45,13 +46,6 @@
#define GLIBC_INITS_RSEQ
#endif
#endif
-
-// Before kernel 4.17, Linux did not support MAP_FIXED_NOREPLACE, so if it is
-// not available, simplfy define it as MAP_FIXED which performs the same
-// function but does not guarantee existing mappings won't get clobbered.
-#ifndef MAP_FIXED_NOREPLACE
-#define MAP_FIXED_NOREPLACE MAP_FIXED
-#endif
#endif // __linux__
namespace llvm {
diff --git a/llvm/tools/llvm-exegesis/lib/MmapUtils.h b/llvm/tools/llvm-exegesis/lib/MmapUtils.h
new file mode 100644
index 00000000000000..31e8778ce8d40a
--- /dev/null
+++ b/llvm/tools/llvm-exegesis/lib/MmapUtils.h
@@ -0,0 +1,32 @@
+//===-- MmapUtils.h ---------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains compatibility-related preprocessor directives related
+// to mmap.
+//
+//===----------------------------------------------------------------------===//
+
+#ifdef __linux__
+#include <sys/mman.h>
+#include <sys/syscall.h>
+
+// Before kernel 4.17, Linux did not support MAP_FIXED_NOREPLACE, so if it is
+// not available, simplfy define it as MAP_FIXED which performs the same
+// function but does not guarantee existing mappings won't get clobbered.
+#ifndef MAP_FIXED_NOREPLACE
+#define MAP_FIXED_NOREPLACE MAP_FIXED
+#endif
+
+// Some 32-bit architectures don't have mmap and define mmap2 instead. The only
+//
diff erence between the two syscalls is that mmap2's offset parameter is in
+// terms 4096 byte offsets rather than individual bytes, so for our purposes
+// they are effectively the same as all ofsets here are set to 0.
+#if defined(SYS_mmap2) && !defined(SYS_mmap)
+#define SYS_mmap SYS_mmap2
+#endif
+#endif // __linux__
diff --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
index 73c0f5430d80d1..2c2d1adb0fcf08 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
@@ -8,6 +8,7 @@
#include "../Target.h"
#include "../Error.h"
+#include "../MmapUtils.h"
#include "../ParallelSnippetGenerator.h"
#include "../SerialSnippetGenerator.h"
#include "../SnippetGenerator.h"
@@ -1080,21 +1081,6 @@ ExegesisX86Target::generateExitSyscall(unsigned ExitCode) const {
return ExitCallCode;
}
-// Before kernel 4.17, Linux did not support MAP_FIXED_NOREPLACE, so if it is
-// not available, simplfy define it as MAP_FIXED which performs the same
-// function but does not guarantee existing mappings won't get clobbered.
-#ifndef MAP_FIXED_NOREPLACE
-#define MAP_FIXED_NOREPLACE MAP_FIXED
-#endif
-
-// Some 32-bit architectures don't have mmap and define mmap2 instead. The only
-//
diff erence between the two syscalls is that mmap2's offset parameter is in
-// terms 4096 byte offsets rather than individual bytes, so for our purposes
-// they are effectively the same as all ofsets here are set to 0.
-#if defined(SYS_mmap2) && !defined(SYS_mmap)
-#define SYS_mmap SYS_mmap2
-#endif
-
std::vector<MCInst>
ExegesisX86Target::generateMmap(intptr_t Address, size_t Length,
intptr_t FileDescriptorAddress) const {
diff --git a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
index ff0810e984dd78..e0427664d2c3cf 100644
--- a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
@@ -12,6 +12,7 @@
#include <memory>
#include "MCTargetDesc/X86MCTargetDesc.h"
+#include "MmapUtils.h"
#include "SubprocessMemory.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
@@ -625,21 +626,6 @@ TEST_F(X86Core2TargetTest, GenerateExitSyscallTest) {
OpcodeIs(X86::SYSCALL)));
}
-// Before kernel 4.17, Linux did not support MAP_FIXED_NOREPLACE, so if it is
-// not available, simplfy define it as MAP_FIXED which performs the same
-// function but does not guarantee existing mappings won't get clobbered.
-#ifndef MAP_FIXED_NOREPLACE
-#define MAP_FIXED_NOREPLACE MAP_FIXED
-#endif
-
-// Some 32-bit architectures don't have mmap and define mmap2 instead. The only
-//
diff erence between the two syscalls is that mmap2's offset parameter is in
-// terms 4096 byte offsets rather than individual bytes, so for our purposes
-// they are effectively the same as all ofsets here are set to 0.
-#if defined(SYS_mmap2) && !defined(SYS_mmap)
-#define SYS_mmap SYS_mmap2
-#endif
-
TEST_F(X86Core2TargetTest, GenerateMmapTest) {
EXPECT_THAT(State.getExegesisTarget().generateMmap(0x1000, 4096, 0x2000),
ElementsAre(IsMovImmediate(X86::MOV64ri, X86::RDI, 0x1000),
More information about the llvm-commits
mailing list