[refactor] Move inlineCost and inlineCost3 to a visitor class