Page MenuHomePhabricator

[NFC] Introduce SwitchInst wrapper for prof branch_weights handling
ClosedPublic

Authored by yrouban on May 19 2019, 11:53 PM.

Details

Summary

This patch introduces a wrapper class that re-implements several mutator methods of SwitchInst to handle changes of prof branch_weights metadata along with remove/add switch case methods.
Subsequent patches will use this wrapper to implement prof branch_weights metadata handling for SwitchInst.

This patch is a redesigned way of prof branch_weights handling proposed in D60554 and D60604. It does not change contract of SwitchInst.

Diff Detail

Repository
rL LLVM

Event Timeline

yrouban created this revision.May 19 2019, 11:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2019, 11:53 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
davidxl added inline comments.May 21 2019, 9:24 AM
llvm/include/llvm/IR/Instructions.h
3440 ↗(On Diff #200206)

Nit: Perhaps name it SwitchInstProfUpdateWrapper ? The original name implies that SwitchInst does not have prof weights which is misleading.

3455 ↗(On Diff #200206)

nit: is it necessary to have 3 things doing the same thing?

3466 ↗(On Diff #200206)

add documentation comment.

3468 ↗(On Diff #200206)

same here.

llvm/lib/IR/Instructions.cpp
3891 ↗(On Diff #200206)

Add sanity check that number of cases matches weights size?

yrouban marked 5 inline comments as done.May 22 2019, 8:07 AM
yrouban added inline comments.
llvm/include/llvm/IR/Instructions.h
3455 ↗(On Diff #200206)

This is a syntax sugar which allows us to minimize code changes in subsequent patches.
E.g.
SwitchInst *SI = x; is changed to SwitchInstProfBranchWeightsWrapper SI = x;
Then we can keep unchanged calls like SI->methods() or sending parameters of type SwitchInst* or SwitchInst&.

yrouban updated this revision to Diff 200750.May 22 2019, 8:11 AM

Addressed comments:

  • renamed to SwitchInstProfUpdateWrapper
  • added method descriptions
  • added one assertion
davidxl accepted this revision.May 23 2019, 4:41 PM

lgtm

This revision is now accepted and ready to land.May 23 2019, 4:41 PM
This revision was automatically updated to reflect the committed changes.