This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Instrumentation: Initial instrumentation support for AArch64
ClosedPublic

Authored by Elvina on Jun 1 2023, 9:36 AM.

Details

Summary

This patch adds code generation for AArch64 instrumentation, including direct and indirect calls support.

Elvina Yakubova,
Advanced Software Technology Lab, Huawei

Diff Detail

Event Timeline

Elvina created this revision.Jun 1 2023, 9:36 AM
Elvina requested review of this revision.Jun 1 2023, 9:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2023, 9:36 AM
Amir added a comment.Jun 1 2023, 12:04 PM

@maksfb – looks like we really need to add target-specific passes to avoid having all target-specific interfaces exposed through MCPlusBuilder.

Elvina updated this revision to Diff 527865.Jun 2 2023, 8:11 AM
Elvina removed a reviewer: rafaelauler.

clang-format

@maksfb – looks like we really need to add target-specific passes to avoid having all target-specific interfaces exposed through MCPlusBuilder.

Totally :)

rafauler added inline comments.Jun 22 2023, 2:57 PM
bolt/include/bolt/Core/MCPlusBuilder.h
469–504

These 6 new member functions being added here are only locally used inside AArch64MCPlusBuilder.cpp, correct? If that's the case, remove them from the architecture-independent interface (MCPlusBuilder.h) and declare them as helper functions/local definitions inside AArch64MCPlusBuilder.cpp outside of the class. I don't think they need to be member functions, so they can have visibility limited to the AArch64 file, e.g.:

static void createPushRegisters(MCInst...
  Inst.clear();
  ...
}

InstructionListType createInstrumentedIndirectCall(MCInst &&CallInst,
                                                   MCSymbol *HandlerFuncAddr,
                                                   int CallSiteID,
                                                   MCContext *Ctx) override {
  ...
  createPushRegisters(...)
1612–1622

Same for these functions. In general the idea is to avoid unnecessarily exporting functions to the generic architecture-independent interface because by doing so we are suggesting that other architectures should implement these functions, and we're further implying BOLT will use them somewhere in the architecture-independent code, when in reality we're just using them internally in our AArch64 implementation.

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
1590

Do we support 32-bit pointers for AArch64? If not, I would just hardcode AArch64::SP here and in other locations an drop the CodePointerSize argument. If we do support, I think it would be nice to have tests that show we are working correctly for these binaries.

rafauler added inline comments.Jun 26 2023, 5:15 PM
bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
1507

Why not X0, X1 directly here? Doesn't look like X0 is a temporary register, btw, so I think the naming of "TempReg" is a bit off here.

rafauler added inline comments.Jun 26 2023, 5:50 PM
bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
1428

getIntArgRegister(1) should be replaced with AArch64::X1

1445

Don't we need to remove the tailcall annotation like in the X86 code?

1470

Shift

1471

I

1524–1528

This is not doing what the comment says -- try the same sequence used in X86:

stripAnnotations(Insts.back())
moveAnnotations(std::move(CallInst), Insts.back());
1548

same - delete TempReg and use X0 directly like you do on line 1451

Elvina updated this revision to Diff 536232.Jun 30 2023, 7:22 AM

updated diff according to comments

Elvina marked 10 inline comments as done.Jun 30 2023, 7:28 AM

Thanks for reviewing this! Fixed everything you mentioned

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
1445

right, thanks for pointing this

1590

currently no, so SP is enough

Elvina updated this revision to Diff 548224.Aug 8 2023, 7:56 AM
Elvina marked 2 inline comments as done.

rebase

rafauler accepted this revision.Aug 18 2023, 5:36 PM

I think you forgot to delete the now unnecessary CodePointerSize parameter.

Other than that, looks good! Thanks for working on this. Unfortunately, I don't have an AArch64 machine to test this more thoroughly, so I'm assuming somebody with one of these machines tested your changes? On my side this LGTM, if @yota9 would like to, he can chime in to test this on real AArch64 machines.

This revision is now accepted and ready to land.Aug 18 2023, 5:36 PM
Elvina updated this revision to Diff 552030.Aug 21 2023, 8:31 AM

remove CodePointerSize parameter

Elvina updated this revision to Diff 553113.Aug 24 2023, 7:49 AM

removed BL and B checks in convertIndirectCallToLoad

yota9 accepted this revision.Aug 24 2023, 8:39 AM
yota9 added a subscriber: rafaelauler.

LGTM. @rafaelauler the patches were tested on our ARM servers successfully, so I think they're good to go :)