[PATCH] D110789: BPF: implement isLegalAddressingMode() properly

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 30 16:07:21 PDT 2021


yonghong-song updated this revision to Diff 376393.
yonghong-song retitled this revision from "BPF: implement TTI->getGEPCost() properly" to "BPF: implement isLegalAddressingMode() properly".
yonghong-song edited the summary of this revision.
yonghong-song added a comment.
Herald added subscribers: atanasyan, arichardson, sdardis.

Implement isLegalAddressingMode() instead of getGEPCost()


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110789/new/

https://reviews.llvm.org/D110789

Files:
  llvm/lib/Target/BPF/BPFISelLowering.cpp
  llvm/lib/Target/BPF/BPFISelLowering.h


Index: llvm/lib/Target/BPF/BPFISelLowering.h
===================================================================
--- llvm/lib/Target/BPF/BPFISelLowering.h
+++ llvm/lib/Target/BPF/BPFISelLowering.h
@@ -130,6 +130,10 @@
     return false;
   }
 
+  bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
+                             Type *Ty, unsigned AS,
+                             Instruction *I = nullptr) const override;
+
   // isTruncateFree - Return true if it's free to truncate a value of
   // type Ty1 to type Ty2. e.g. On BPF at alu32 mode, it's free to truncate
   // a i64 value in register R1 to i32 by referencing its sub-register W1.
Index: llvm/lib/Target/BPF/BPFISelLowering.cpp
===================================================================
--- llvm/lib/Target/BPF/BPFISelLowering.cpp
+++ llvm/lib/Target/BPF/BPFISelLowering.cpp
@@ -859,3 +859,25 @@
                                               EVT VT) const {
   return (getHasAlu32() && VT == MVT::i32) ? MVT::i32 : MVT::i64;
 }
+
+bool BPFTargetLowering::isLegalAddressingMode(const DataLayout &DL,
+                                              const AddrMode &AM, Type *Ty,
+                                              unsigned AS,
+                                              Instruction *I) const {
+  // No global is ever allowed as a base.
+  if (AM.BaseGV)
+    return false;
+
+  switch (AM.Scale) {
+  case 0: // "r+i" or just "i", depending on HasBaseReg.
+    break;
+  case 1:
+    if (!AM.HasBaseReg) // allow "r+i".
+      break;
+    return false; // disallow "r+r" or "r+r+i".
+  default:
+    return false;
+  }
+
+  return true;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110789.376393.patch
Type: text/x-patch
Size: 1650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210930/129f9ef5/attachment.bin>


More information about the llvm-commits mailing list