This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC][Future] Add initial support for PC Relative addressing to get block address
ClosedPublic

Authored by NeHuang on Mar 17 2020, 9:30 AM.

Details

Summary

Add initial support for PCRelative addressing to get block address instead of using TOC.

Diff Detail

Event Timeline

NeHuang created this revision.Mar 17 2020, 9:30 AM
NeHuang retitled this revision from [PowerPC][Future] Add initial support for PC Relative addressing to get block address base address to [PowerPC][Future] Add initial support for PC Relative addressing to get block address .Mar 17 2020, 9:33 AM
jsji added a reviewer: Restricted Project.Mar 17 2020, 10:36 AM
jsji added a project: Restricted Project.
amyk added a subscriber: amyk.Mar 21 2020, 3:31 PM
amyk added inline comments.
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
2908

I think it would be good if we can put a comment above briefly saying what happens when we have PC relative mem ops.

nemanjai accepted this revision.Mar 23 2020, 1:39 PM

LGTM aside from some nits that should be easily addressable on the commit.

llvm/lib/Target/PowerPC/PPCISelLowering.cpp
2557

This is starting to get unnecessary. There is no reason to have all the different bool variables.
Something like this might be more readable:

  bool ValidPCRelNode = false;
#define VALIDATE_PCREL_NODE(TYPE)                                              \
  {                                                                            \
    TYPE *PCRelCand = dyn_cast<TYPE>(N);                                       \
    if (PCRelCand && PCRelCand->getTargetFlags() == PPCII::MO_PCREL_FLAG)      \
      ValidPCRelNode = true;                                                   \
  }
  VALIDATE_PCREL_NODE(ConstantPoolSDNode);
  VALIDATE_PCREL_NODE(GlobalAddressSDNode);
  VALIDATE_PCREL_NODE(JumpTableSDNode);
  VALIDATE_PCREL_NODE(BlockAddressSDNode);
  if (ValidPCRelNode) {
    Base = N;
    return true;
  }
  return false;
#undef VALIDATE_PCREL_NODE

Or define a template such as:

template <typename Ty> static bool isValidPCRelNode(SDValue N) {
  Ty *PCRelCand = dyn_cast<Ty>(N);
  return PCRelCand && PCRelCand->getTargetFlags() == PPCII::MO_PCREL_FLAG;
}

And then this function is just:

if (isValidPCRelNode<ConstantPoolSDNode>(N) ||
    isValidPCRelNode<GlobalAddressSDNode>(N) ||
    isValidPCRelNode<JumpTableSDNode>(N) ||
    isValidPCRelNode<BlockAddressSDNode>(N)) {
  Base = N;
  return true;
}
return false;

My preference being for the latter.

2908

Remove this from the AIX block as there is no PC-Rel on AIX.

This revision is now accepted and ready to land.Mar 23 2020, 1:39 PM
NeHuang marked 3 inline comments as done.Apr 8 2020, 12:48 PM
NeHuang updated this revision to Diff 258163.Apr 16 2020, 1:41 PM

Address review comment

This revision was automatically updated to reflect the committed changes.