Skip to content

[llvm-exegesis] Switch from intptr_t to uintptr_t in most cases #102860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/tools/llvm-exegesis/lib/Assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/llvm-exegesis/lib/BenchmarkResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
15 changes: 8 additions & 7 deletions llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -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(),
Expand All @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions llvm/tools/llvm-exegesis/lib/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/llvm-exegesis/lib/SnippetFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions llvm/tools/llvm-exegesis/lib/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down
16 changes: 8 additions & 8 deletions llvm/tools/llvm-exegesis/lib/X86/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/tools/llvm-exegesis/BenchmarkRunnerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading