[PATCH] D91050: [NFC] Add the getConstantPool hook for target to customize it with MachineConstantPoolValue

Qing Shan Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 9 00:14:59 PST 2020


steven.zhang created this revision.
steven.zhang added reviewers: MaskRay, RKSimon, echristo, spatel, PowerPC.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
steven.zhang requested review of this revision.

We have the MachineConstantPoolValue to allow the target to customize the lowering of the constant. But when we are trying to legalize the constant, it is still forced to use the ConstantPool and target has no way to customize it with MachineConstantPoolValue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91050

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -328,9 +328,9 @@
     }
   }
 
-  SDValue CPIdx =
-      DAG.getConstantPool(LLVMC, TLI.getPointerTy(DAG.getDataLayout()));
-  Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
+  Align Alignment;
+  SDValue CPIdx = TLI.getConstantPool(LLVMC, DAG, Alignment,
+                                      TLI.getPointerTy(DAG.getDataLayout()));
   if (Extend) {
     SDValue Result = DAG.getExtLoad(
         ISD::EXTLOAD, dl, OrigVT, DAG.getEntryNode(), CPIdx,
@@ -347,10 +347,10 @@
 /// Expands the Constant node to a load from the constant pool.
 SDValue SelectionDAGLegalize::ExpandConstant(ConstantSDNode *CP) {
   SDLoc dl(CP);
+  Align Alignment;
   EVT VT = CP->getValueType(0);
-  SDValue CPIdx = DAG.getConstantPool(CP->getConstantIntValue(),
+  SDValue CPIdx = TLI.getConstantPool(CP->getConstantIntValue(), DAG, Alignment,
                                       TLI.getPointerTy(DAG.getDataLayout()));
-  Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
   SDValue Result = DAG.getLoad(
       VT, dl, DAG.getEntryNode(), CPIdx,
       MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), Alignment);
@@ -2010,10 +2010,10 @@
         CV.push_back(UndefValue::get(OpNTy));
       }
     }
+    Align Alignment;
     Constant *CP = ConstantVector::get(CV);
-    SDValue CPIdx =
-        DAG.getConstantPool(CP, TLI.getPointerTy(DAG.getDataLayout()));
-    Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
+    SDValue CPIdx = TLI.getConstantPool(CP, DAG, Alignment,
+                                        TLI.getPointerTy(DAG.getDataLayout()));
     return DAG.getLoad(
         VT, dl, DAG.getEntryNode(), CPIdx,
         MachinePointerInfo::getConstantPool(DAG.getMachineFunction()),
@@ -2557,9 +2557,9 @@
   Constant *FudgeFactor = ConstantInt::get(
                                        Type::getInt64Ty(*DAG.getContext()), FF);
 
-  SDValue CPIdx =
-      DAG.getConstantPool(FudgeFactor, TLI.getPointerTy(DAG.getDataLayout()));
-  Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
+  Align Alignment;
+  SDValue CPIdx = TLI.getConstantPool(FudgeFactor, DAG, Alignment,
+                                      TLI.getPointerTy(DAG.getDataLayout()));
   CPIdx = DAG.getNode(ISD::ADD, dl, CPIdx.getValueType(), CPIdx, CstOffset);
   Alignment = commonAlignment(Alignment, 4);
   SDValue FudgeInReg;
Index: llvm/include/llvm/CodeGen/TargetLowering.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetLowering.h
+++ llvm/include/llvm/CodeGen/TargetLowering.h
@@ -3601,6 +3601,19 @@
     llvm_unreachable("Not Implemented");
   }
 
+  /// Create target specific constant pool and set the new alignment in
+  /// \p NewAlign
+  virtual SDValue getConstantPool(const Constant *C, SelectionDAG &DAG,
+                                  Align &NewAlign, EVT VT,
+                                  MaybeAlign Align = None, int Offset = 0,
+                                  bool isTarget = false,
+                                  unsigned TargetFlags = 0) const {
+    SDValue CPIdx =
+        DAG.getConstantPool(C, VT, Align, Offset, isTarget, TargetFlags);
+    NewAlign = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
+    return CPIdx;
+  }
+
   /// Return the newly negated expression if the cost is not expensive and
   /// set the cost in \p Cost to indicate that if it is cheaper or neutral to
   /// do the negation.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91050.303760.patch
Type: text/x-patch
Size: 3670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201109/d86f7891/attachment.bin>


More information about the llvm-commits mailing list