Skip to content

[SandboxIR][NFC] Introduce templated CastInstImpl to simplify subclasses #101427

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 1, 2024

Conversation

aeubanks
Copy link
Contributor

The CastInst subclasses all have pretty much the same implementation. Add a helper templated class to help stamp out the subclasses more succinctly.

The CastInst subclasses all have pretty much the same implementation.
Add a helper templated class to help stamp out the subclasses more
succinctly.
class SIToFPInst final : public CastInstImpl<Instruction::Opcode::SIToFP> {};
class FPToUIInst final : public CastInstImpl<Instruction::Opcode::FPToUI> {};
class FPToSIInst final : public CastInstImpl<Instruction::Opcode::FPToSI> {};
class IntToPtrInst final : public CastInstImpl<Instruction::Opcode::IntToPtr> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format shrug

}
#ifndef NDEBUG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep these for now until we find a better fix for all of them. The issue is that gdb won't work with I->dump() if I is a pointer to a sub-class of CastInst. You can get it to work by casting it to sandboxir::CastInst *, like (gdb) ((sandboxir::CastInst *)I)->dump() which is annoying.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like all dump() methods are the same right now, with multi-instructions being different in the future. there's gotta be a better way of deduplicating some of the logic, seeing so many copies of

void FooInst::dump(raw_ostream &OS) const {
  dumpCommonPrefix(OS);
  dumpCommonSuffix(OS);
}

hurts.

can you test if B().f() in

struct A {
    void f();
};

struct B : A {
    using A::f;
};

works with gdb?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there is a ton of duplication. What might work is a non-virtual Value::dump() that calls virtual dumpImpl() that may get overriden by the sub-classes if needed.

I added a using CastInst::dump in SIToFPInst, but gdb still complains: Couldn't find method llvm::sandboxir::SIToFPInst::dump.

Copy link
Contributor

@vporpo vporpo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need a Value::dump() with a big switch case. I will work on that once I add the dump tests.
Anyway, feel free to drop the dumps, I think we can live without them for now.

@aeubanks aeubanks merged commit d68a4d5 into llvm:main Aug 1, 2024
5 of 7 checks passed
@aeubanks aeubanks deleted the sandboxir-cast branch August 1, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants