Skip to content
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

[RuntimeDyld] Add LoongArch support #114741

Merged

Conversation

wangleiat
Copy link
Contributor

This is necessary for supporting function calls in LLDB expressions for
LoongArch.
This patch is inspired by #99336 and simply extracts the parts related
to RuntimeDyld.

Created using spr 1.3.5-bogner
Copy link
Contributor

@SixWeining SixWeining left a comment

Choose a reason for hiding this comment

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

Hi @lhames, we know MCJIT/RuntimeDyld are going to be removed, but this change is necessary to get LoongArch support in lldb (#114742). And LoongArch has already supported ORCJIT and JITLink and it has been verified in production environments (e.g. mesa3d llvmpipe). That means lldb can switch to ORCJIT/JITLink before MCJIT/RuntimeDyld being removed without breaking LoongArch support.

I hope this could be reviewed and merged. Thanks. :)

cc @DavidSpickett

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

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

Not an expert here, just some generic comments.

unsigned RelType = RelI->getType();
// Look for an existing stub.
StubMap::const_iterator i = Stubs.find(Value);
if (i != Stubs.end()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This logic might be easier to parse if it was organised like this:

if (i != Stubs.end()) {
  // resolve using the stub
  return;
}

if (resolveLoongArch64ShortBranch(SectionID, RelI, Value))
  return;

// Create a new stub function.
LLVM_DEBUG(dbgs() << " Create a new stub function\n");

Same logic, but it's easier to see that all paths will resolve the relocation in some way.

Also do you want to prefer stubs over a short branch if you could use one? That seems to be what this does, but I don't know enough about JIT to say if that makes sense.

My assumption is that anything that could be resolved by a short branch would never have needed a stub, so looking for a stub for it will always fail. Perhaps sometimes the same location must be reached via a stub if you are too far away, but if you are close enough for a short branch wouldn't that be the most efficient option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you very much; I will revise it to a clearer logic.

// Returns extract bits Val[Hi:Lo].
static inline uint32_t extractBits(uint64_t Val, uint32_t Hi, uint32_t Lo) {
return Hi == 63 ? Val >> Lo : (Val & (((1ULL << (Hi + 1)) - 1))) >> Lo;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would have thought we would have this in llvm's utility headers somewhere but I couldn't find one. llvm/include/llvm/Support/MathExtras.h is closest but it only has upper and lower 32 bits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it needs to support extracting the entire 64-bit number.

Created using spr 1.3.5-bogner
Copy link
Contributor

@lhames lhames left a comment

Choose a reason for hiding this comment

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

Hi @lhames, we know MCJIT/RuntimeDyld are going to be removed, but this change is necessary to get LoongArch support in lldb (#114742).

We're actually working to get LLDB moved over to ORC, but that will take a little while. This seems like a reasonable step in the mean time. Thanks for working on this @wangleiat !

@wangleiat wangleiat merged commit 4e668d5 into main Nov 8, 2024
6 of 8 checks passed
@wangleiat wangleiat deleted the users/wangleiat/spr/runtimedyld-add-loongarch-support branch November 8, 2024 02:42
wangleiat added a commit that referenced this pull request Nov 8, 2024
This patch adds desired feature flags in JIT compiler to enable
hard-float instructions if target supports them and allows to use floats
and doubles in lldb expressions.

Fited tests:
lldb-shell :: Expr/TestAnonNamespaceParamFunc.cpp
lldb-shell :: Expr/TestIRMemoryMap.test
lldb-shell :: Expr/TestStringLiteralExpr.test
lldb-shell :: SymbolFile/DWARF/debug-types-expressions.test

Similar as #99336
Depens on: #114741

Reviewed By: SixWeining

Pull Request: #114742
Groverkss pushed a commit to iree-org/llvm-project that referenced this pull request Nov 15, 2024
This is necessary for supporting function calls in LLDB expressions for
LoongArch.
This patch is inspired by llvm#99336 and simply extracts the parts related
to RuntimeDyld.

Reviewed By: lhames

Pull Request: llvm#114741
Groverkss pushed a commit to iree-org/llvm-project that referenced this pull request Nov 15, 2024
This patch adds desired feature flags in JIT compiler to enable
hard-float instructions if target supports them and allows to use floats
and doubles in lldb expressions.

Fited tests:
lldb-shell :: Expr/TestAnonNamespaceParamFunc.cpp
lldb-shell :: Expr/TestIRMemoryMap.test
lldb-shell :: Expr/TestStringLiteralExpr.test
lldb-shell :: SymbolFile/DWARF/debug-types-expressions.test

Similar as llvm#99336
Depens on: llvm#114741

Reviewed By: SixWeining

Pull Request: llvm#114742
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.

4 participants