[llvm] fac87b8 - [llvm-exegesis] Switch from intptr_t to uintptr_t in most cases (#102860)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 11:19:51 PDT 2024
Author: Aiden Grossman
Date: 2024-08-27T11:19:44-07:00
New Revision: fac87b889c50f493ba332950f613fa15a45be9a9
URL: https://github.com/llvm/llvm-project/commit/fac87b889c50f493ba332950f613fa15a45be9a9
DIFF: https://github.com/llvm/llvm-project/commit/fac87b889c50f493ba332950f613fa15a45be9a9.diff
LOG: [llvm-exegesis] Switch from intptr_t to uintptr_t in most cases (#102860)
This patch switches most of the uses of intptr_t to uintptr_t within
llvm-exegesis for the subprocess memory support. In the vast majority of
cases we do not want a signed component of the address, hence making
intptr_t undesirable. intptr_t is left for error handling, for example
when making syscalls and we need to see if the syscall returned -1.
Added:
Modified:
llvm/tools/llvm-exegesis/lib/Assembler.h
llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/Error.h
llvm/tools/llvm-exegesis/lib/SnippetFile.cpp
llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
llvm/tools/llvm-exegesis/lib/Target.h
llvm/tools/llvm-exegesis/lib/X86/Target.cpp
llvm/unittests/tools/llvm-exegesis/BenchmarkRunnerTest.cpp
llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp
llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp
llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.h b/llvm/tools/llvm-exegesis/lib/Assembler.h
index d85d7fdcf04f54..198b8754468098 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.h
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.h
@@ -115,7 +115,7 @@ class ExecutableFunction {
// Executes the function.
void operator()(char *Memory) const {
- ((void (*)(char *))(intptr_t)FunctionBytes.data())(Memory);
+ ((void (*)(char *))(uintptr_t)FunctionBytes.data())(Memory);
}
StringRef FunctionBytes;
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
index 4ae6bc2a54cd50..3c09a8380146e5 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
@@ -53,7 +53,7 @@ struct MemoryValue {
struct MemoryMapping {
// The address to place the mapping at.
- intptr_t Address;
+ uintptr_t Address;
// The name of the value that should be mapped.
std::string MemoryValueName;
};
@@ -73,7 +73,7 @@ struct BenchmarkKey {
std::string Config;
// The address that the snippet should be loaded in at if the execution mode
// being used supports it.
- intptr_t SnippetAddress = 0;
+ uintptr_t SnippetAddress = 0;
// The register that should be used to hold the loop counter.
unsigned LoopRegister;
};
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index adee869967d98a..fd98af8a9e6adb 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -379,7 +379,7 @@ class SubProcessFunctionExecutorImpl
if (ChildSignalInfo.si_signo == SIGSEGV)
return make_error<SnippetSegmentationFault>(
- reinterpret_cast<intptr_t>(ChildSignalInfo.si_addr));
+ reinterpret_cast<uintptr_t>(ChildSignalInfo.si_addr));
return make_error<SnippetSignal>(ChildSignalInfo.si_signo);
}
@@ -477,9 +477,10 @@ class SubProcessFunctionExecutorImpl
if (__rseq_size < 32)
RseqStructSize = 32;
- long RseqDisableOutput =
- syscall(SYS_rseq, (intptr_t)__builtin_thread_pointer() + __rseq_offset,
- RseqStructSize, RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
+ long RseqDisableOutput = syscall(
+ SYS_rseq,
+ reinterpret_cast<uintptr_t>(__builtin_thread_pointer()) + __rseq_offset,
+ RseqStructSize, RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
if (RseqDisableOutput != 0)
exit(ChildProcessExitCodeE::RSeqDisableFailed);
#endif // GLIBC_INITS_RSEQ
@@ -502,7 +503,7 @@ class SubProcessFunctionExecutorImpl
char *FunctionDataCopy =
(char *)mmap(MapAddress, FunctionDataCopySize, PROT_READ | PROT_WRITE,
MapFlags, 0, 0);
- if ((intptr_t)FunctionDataCopy == -1)
+ if (reinterpret_cast<intptr_t>(FunctionDataCopy) == -1)
exit(ChildProcessExitCodeE::FunctionDataMappingFailed);
memcpy(FunctionDataCopy, this->Function.FunctionBytes.data(),
@@ -515,8 +516,8 @@ class SubProcessFunctionExecutorImpl
if (!AuxMemFDOrError)
exit(ChildProcessExitCodeE::AuxiliaryMemorySetupFailed);
- ((void (*)(size_t, int))(intptr_t)FunctionDataCopy)(FunctionDataCopySize,
- *AuxMemFDOrError);
+ ((void (*)(size_t, int))(uintptr_t)FunctionDataCopy)(FunctionDataCopySize,
+ *AuxMemFDOrError);
exit(0);
}
diff --git a/llvm/tools/llvm-exegesis/lib/Error.h b/llvm/tools/llvm-exegesis/lib/Error.h
index 2587c45f557434..4a3e48997f24f6 100644
--- a/llvm/tools/llvm-exegesis/lib/Error.h
+++ b/llvm/tools/llvm-exegesis/lib/Error.h
@@ -52,15 +52,15 @@ class SnippetExecutionFailure : public ErrorInfo<SnippetExecutionFailure> {
class SnippetSegmentationFault : public SnippetExecutionFailure {
public:
static char ID;
- SnippetSegmentationFault(intptr_t SegFaultAddress)
- : Address(SegFaultAddress){};
+ SnippetSegmentationFault(uintptr_t SegFaultAddress)
+ : Address(SegFaultAddress) {};
- intptr_t getAddress() { return Address; }
+ uintptr_t getAddress() { return Address; }
void log(raw_ostream &OS) const override;
private:
- intptr_t Address;
+ uintptr_t Address;
};
// A class representing all other non-specific failures that happen during
diff --git a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp
index 08da04cc62d9cf..4f16d0ba0cef37 100644
--- a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp
@@ -151,8 +151,8 @@ class BenchmarkCodeStreamer : public MCStreamer, public AsmCommentConsumer {
}
if (CommentText.consume_front("SNIPPET-ADDRESS")) {
// LLVM-EXEGESIS-SNIPPET-ADDRESS <address>
- if (!to_integer<intptr_t>(CommentText.trim(), Result->Key.SnippetAddress,
- 16)) {
+ if (!to_integer<uintptr_t>(CommentText.trim(), Result->Key.SnippetAddress,
+ 16)) {
errs() << "invalid comment 'LLVM-EXEGESIS-SNIPPET-ADDRESS "
<< CommentText
<< "', expected <ADDRESS> to contain a valid integer in "
diff --git a/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp b/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
index 89d7b197079e4f..ce0ce918ae0d7b 100644
--- a/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
@@ -126,7 +126,7 @@ Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
int *AuxiliaryMemoryMapping =
(int *)mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED,
AuxiliaryMemoryFileDescriptor, 0);
- if ((intptr_t)AuxiliaryMemoryMapping == -1)
+ if (reinterpret_cast<intptr_t>(AuxiliaryMemoryMapping) == -1)
return make_error<Failure>("Mapping auxiliary memory failed");
AuxiliaryMemoryMapping[0] = CounterFileDescriptor;
for (auto &[Name, MemVal] : MemoryDefinitions) {
diff --git a/llvm/tools/llvm-exegesis/lib/Target.h b/llvm/tools/llvm-exegesis/lib/Target.h
index 522c75d15703d5..92cc1cb248a1c0 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.h
+++ b/llvm/tools/llvm-exegesis/lib/Target.h
@@ -118,8 +118,8 @@ class ExegesisTarget {
// Generates the code to mmap a region of code. The code generated by this
// function may clobber registers.
virtual std::vector<MCInst>
- generateMmap(intptr_t Address, size_t Length,
- intptr_t FileDescriptorAddress) const {
+ generateMmap(uintptr_t Address, size_t Length,
+ uintptr_t FileDescriptorAddress) const {
report_fatal_error(
"generateMmap is not implemented on the current architecture");
}
@@ -161,7 +161,7 @@ class ExegesisTarget {
"current architectures");
}
- virtual intptr_t getAuxiliaryMemoryStartAddress() const {
+ virtual uintptr_t getAuxiliaryMemoryStartAddress() const {
report_fatal_error("getAuxiliaryMemoryStartAddress is not implemented on "
"the current architecture");
}
diff --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
index dbb2bf409316e7..4709dede5b2e20 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
@@ -747,8 +747,8 @@ class ExegesisX86Target : public ExegesisTarget {
std::vector<MCInst> generateExitSyscall(unsigned ExitCode) const override;
std::vector<MCInst>
- generateMmap(intptr_t Address, size_t Length,
- intptr_t FileDescriptorAddress) const override;
+ generateMmap(uintptr_t Address, size_t Length,
+ uintptr_t FileDescriptorAddress) const override;
void generateMmapAuxMem(std::vector<MCInst> &GeneratedCode) const override;
@@ -758,7 +758,7 @@ class ExegesisX86Target : public ExegesisTarget {
std::vector<MCInst> setStackRegisterToAuxMem() const override;
- intptr_t getAuxiliaryMemoryStartAddress() const override;
+ uintptr_t getAuxiliaryMemoryStartAddress() const override;
std::vector<MCInst> configurePerfCounter(long Request, bool SaveRegisters) const override;
@@ -1091,9 +1091,9 @@ std::vector<MCInst> ExegesisX86Target::setRegTo(const MCSubtargetInfo &STI,
#ifdef __linux__
#ifdef __arm__
-static constexpr const intptr_t VAddressSpaceCeiling = 0xC0000000;
+static constexpr const uintptr_t VAddressSpaceCeiling = 0xC0000000;
#else
-static constexpr const intptr_t VAddressSpaceCeiling = 0x0000800000000000;
+static constexpr const uintptr_t VAddressSpaceCeiling = 0x0000800000000000;
#endif
void generateRoundToNearestPage(unsigned int Register,
@@ -1180,8 +1180,8 @@ ExegesisX86Target::generateExitSyscall(unsigned ExitCode) const {
}
std::vector<MCInst>
-ExegesisX86Target::generateMmap(intptr_t Address, size_t Length,
- intptr_t FileDescriptorAddress) const {
+ExegesisX86Target::generateMmap(uintptr_t Address, size_t Length,
+ uintptr_t FileDescriptorAddress) const {
std::vector<MCInst> MmapCode;
MmapCode.push_back(loadImmediate(X86::RDI, 64, APInt(64, Address)));
MmapCode.push_back(loadImmediate(X86::RSI, 64, APInt(64, Length)));
@@ -1249,7 +1249,7 @@ std::vector<MCInst> ExegesisX86Target::setStackRegisterToAuxMem() const {
SubprocessMemory::AuxiliaryMemorySize)};
}
-intptr_t ExegesisX86Target::getAuxiliaryMemoryStartAddress() const {
+uintptr_t ExegesisX86Target::getAuxiliaryMemoryStartAddress() const {
// Return the second to last page in the virtual address space to try and
// prevent interference with memory annotations in the snippet
return VAddressSpaceCeiling - 2 * getpagesize();
diff --git a/llvm/unittests/tools/llvm-exegesis/BenchmarkRunnerTest.cpp b/llvm/unittests/tools/llvm-exegesis/BenchmarkRunnerTest.cpp
index 9414a48c989e4e..a188a7f266c206 100644
--- a/llvm/unittests/tools/llvm-exegesis/BenchmarkRunnerTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/BenchmarkRunnerTest.cpp
@@ -17,7 +17,7 @@ namespace {
TEST(ScratchSpaceTest, Works) {
BenchmarkRunner::ScratchSpace Space;
- EXPECT_EQ(reinterpret_cast<intptr_t>(Space.ptr()) %
+ EXPECT_EQ(reinterpret_cast<uintptr_t>(Space.ptr()) %
BenchmarkRunner::ScratchSpace::kAlignment,
0u);
Space.ptr()[0] = 42;
diff --git a/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp
index f1fa891171177c..de883ab750d201 100644
--- a/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp
@@ -81,7 +81,8 @@ MATCHER_P3(MemoryDefinitionIs, Name, Value, Size, "") {
}
MATCHER_P2(MemoryMappingIs, Address, Name, "") {
- if (arg.Address == Address && arg.MemoryValueName == Name)
+ if (arg.Address == static_cast<uintptr_t>(Address) &&
+ arg.MemoryValueName == Name)
return true;
*result_listener << "expected: {" << Address << ", " << Name << "} ";
*result_listener << "actual: {" << arg.Address << ", " << arg.MemoryValueName
@@ -216,7 +217,7 @@ TEST_F(X86SnippetFileTest, SnippetAddress) {
ASSERT_TRUE(static_cast<bool>(Snippets));
EXPECT_THAT(*Snippets, SizeIs(1));
const auto &Snippet = (*Snippets)[0];
- EXPECT_EQ(Snippet.Key.SnippetAddress, 0x10000);
+ EXPECT_EQ(Snippet.Key.SnippetAddress, static_cast<uintptr_t>(0x10000));
}
TEST_F(X86SnippetFileTest, LoopRegister) {
diff --git a/llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp
index f61254ac74e140..a0cad289e978f4 100644
--- a/llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp
@@ -64,7 +64,7 @@ class SubprocessMemoryTest : public X86TestBase {
shm_open(DefinitionName.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
uint8_t *SharedMemoryMapping = (uint8_t *)mmap(
NULL, DefinitionSize, PROT_READ, MAP_SHARED, SharedMemoryFD, 0);
- EXPECT_NE((intptr_t)SharedMemoryMapping, -1);
+ EXPECT_NE(reinterpret_cast<intptr_t>(SharedMemoryMapping), -1);
for (size_t I = 0; I < ExpectedValue.size(); ++I) {
EXPECT_EQ(SharedMemoryMapping[I], ExpectedValue[I]);
}
diff --git a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
index e0427664d2c3cf..3a028bad486ccc 100644
--- a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
@@ -599,9 +599,9 @@ TEST_F(X86Core2TargetTest, GenerateLowerMunmapTest) {
}
#ifdef __arm__
-static constexpr const intptr_t VAddressSpaceCeiling = 0xC0000000;
+static constexpr const uintptr_t VAddressSpaceCeiling = 0xC0000000;
#else
-static constexpr const intptr_t VAddressSpaceCeiling = 0x0000800000000000;
+static constexpr const uintptr_t VAddressSpaceCeiling = 0x0000800000000000;
#endif
TEST_F(X86Core2TargetTest, GenerateUpperMunmapTest) {
More information about the llvm-commits
mailing list