-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
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> { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this 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.
The CastInst subclasses all have pretty much the same implementation. Add a helper templated class to help stamp out the subclasses more succinctly.