@@ -1592,11 +1592,25 @@ SDValue XtensaTargetLowering::LowerConstantPool(SDValue Op,
15921592 SelectionDAG &DAG) const {
15931593 EVT PtrVT = Op.getValueType ();
15941594 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
1595+ auto C = const_cast <Constant *>(CP->getConstVal ());
1596+ auto T = const_cast <Type *>(CP->getType ());
15951597 SDValue Result;
15961598
1597- if (!CP->isMachineConstantPoolEntry ()) {
1598- Result = DAG.getTargetConstantPool (CP->getConstVal (), PtrVT, CP->getAlign (),
1599- CP->getOffset ());
1599+ // Do not use constant pool for aggregate or vector constant types,
1600+ // in such cases create global variable
1601+ if (T->isAggregateType () || T->isVectorTy ()) {
1602+ auto AFI = DAG.getMachineFunction ().getInfo <XtensaMachineFunctionInfo>();
1603+ auto M = const_cast <Module *>(
1604+ DAG.getMachineFunction ().getFunction ().getParent ());
1605+ auto GV = new GlobalVariable (
1606+ *M, T, /* isConstant=*/ true , GlobalVariable::InternalLinkage, C,
1607+ Twine (DAG.getDataLayout ().getPrivateGlobalPrefix ()) + " CP" +
1608+ Twine (DAG.getMachineFunction ().getFunctionNumber ()) + " _" +
1609+ Twine (AFI->createCPLabelId ()));
1610+ Result = DAG.getTargetConstantPool (GV, PtrVT, Align (4 ));
1611+ } else if (!CP->isMachineConstantPoolEntry ()) {
1612+ Result =
1613+ DAG.getTargetConstantPool (C, PtrVT, CP->getAlign (), CP->getOffset ());
16001614 } else {
16011615 report_fatal_error (" This constantpool type is not supported yet" );
16021616 }
0 commit comments