llvm.org GIT mirror llvm / 276dcbd
Introduce a new node for holding call argument flags. This is needed by the new legalize types infrastructure which wants to expand the 64 bit constants previously used to hold the flags on 32 bit machines. There are two functional changes: (1) in LowerArguments, if a parameter has the zext attribute set then that is marked in the flags; before it was being ignored; (2) PPC had some bogus code for handling two word arguments when using the ELF 32 ABI, which was hard to convert because of the bogusness. As suggested by the original author (Nicolas Geoffray), I've disabled it for the moment. Tested with "make check" and the Ada ACATS testsuite. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48640 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 12 years ago
13 changed file(s) with 251 addition(s) and 169 deletion(s). Raw diff Collapse all Expand all
9797 /// reflect the change.
9898 typedef bool CCAssignFn(unsigned ValNo, MVT::ValueType ValVT,
9999 MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,
100 ISD::ParamFlags::ParamFlagsTy ArgFlags, CCState &State);
100 ISD::ArgFlagsTy ArgFlags, CCState &State);
101101
102102
103103 /// CCState - This class holds information needed while lowering arguments and
196196 // parameter attribute.
197197 void HandleByVal(unsigned ValNo, MVT::ValueType ValVT,
198198 MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,
199 int MinSize, int MinAlign,
200 ISD::ParamFlags::ParamFlagsTy ArgFlags);
199 int MinSize, int MinAlign, ISD::ArgFlagsTy ArgFlags);
201200
202201 private:
203202 /// MarkAllocated - Mark a register and all of its aliases as allocated.
218218 SDOperand getBasicBlock(MachineBasicBlock *MBB);
219219 SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT);
220220 SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT);
221 SDOperand getArgFlags(ISD::ArgFlagsTy Flags);
221222 SDOperand getValueType(MVT::ValueType);
222223 SDOperand getRegister(unsigned Reg, MVT::ValueType VT);
223224
5555 /// SelectionDAG node types and value types.
5656 ///
5757 namespace ISD {
58 namespace ParamFlags {
59 typedef uint64_t ParamFlagsTy;
60
61 const ParamFlagsTy NoFlagSet = 0ULL;
62 const ParamFlagsTy ZExt = 1ULL<<0; ///< Zero extended
63 const ParamFlagsTy ZExtOffs = 0;
64 const ParamFlagsTy SExt = 1ULL<<1; ///< Sign extended
65 const ParamFlagsTy SExtOffs = 1;
66 const ParamFlagsTy InReg = 1ULL<<2; ///< Passed in register
67 const ParamFlagsTy InRegOffs = 2;
68 const ParamFlagsTy StructReturn = 1ULL<<3; ///< Hidden struct-ret ptr
69 const ParamFlagsTy StructReturnOffs = 3;
70 const ParamFlagsTy ByVal = 1ULL<<4; ///< Struct passed by value
71 const ParamFlagsTy ByValOffs = 4;
72 const ParamFlagsTy Nest = 1ULL<<5; ///< Nested fn static chain
73 const ParamFlagsTy NestOffs = 5;
74 const ParamFlagsTy ByValAlign = 0xFULL << 6; //< Struct alignment
75 const ParamFlagsTy ByValAlignOffs = 6;
76 const ParamFlagsTy OrigAlignment = 0x1FULL<<27;
77 const ParamFlagsTy OrigAlignmentOffs = 27;
78 const ParamFlagsTy ByValSize = 0xffffffffULL << 32; //< Struct size
79 const ParamFlagsTy ByValSizeOffs = 32;
80
81 const ParamFlagsTy One = 1LL; //< 1 of this type, for shifts
82 }
8358
8459 //===--------------------------------------------------------------------===//
8560 /// ISD::NodeType enum - This enum defines all of the operators valid in a
10681 AssertSext, AssertZext,
10782
10883 // Various leaf nodes.
109 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
84 STRING, BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
11085 Constant, ConstantFP,
11186 GlobalAddress, GlobalTLSAddress, FrameIndex,
11287 JumpTable, ConstantPool, ExternalSymbol,
658633 /// computed and is available in the base pointer. The offset
659634 /// operand is always undefined. In addition to producing a
660635 /// chain, an unindexed load produces one value (result of the
661 /// load); an unindexed store does not produces a value.
636 /// load); an unindexed store does not produce a value.
662637 ///
663638 /// PRE_INC Similar to the unindexed mode where the effective address is
664639 /// PRE_DEC the value of the base pointer add / subtract the offset.
15831558 }
15841559 };
15851560
1561 namespace ISD {
1562 struct ArgFlagsTy {
1563 private:
1564 static const uint64_t NoFlagSet = 0ULL;
1565 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
1566 static const uint64_t ZExtOffs = 0;
1567 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
1568 static const uint64_t SExtOffs = 1;
1569 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
1570 static const uint64_t InRegOffs = 2;
1571 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
1572 static const uint64_t SRetOffs = 3;
1573 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
1574 static const uint64_t ByValOffs = 4;
1575 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
1576 static const uint64_t NestOffs = 5;
1577 static const uint64_t ByValAlign = 0xFULL << 6; //< Struct alignment
1578 static const uint64_t ByValAlignOffs = 6;
1579 static const uint64_t OrigAlign = 0x1FULL<<27;
1580 static const uint64_t OrigAlignOffs = 27;
1581 static const uint64_t ByValSize = 0xffffffffULL << 32; //< Struct size
1582 static const uint64_t ByValSizeOffs = 32;
1583
1584 static const uint64_t One = 1ULL; //< 1 of this type, for shifts
1585
1586 uint64_t Flags;
1587 public:
1588 ArgFlagsTy() : Flags(0) { }
1589
1590 bool isZExt() const { return Flags & ZExt; }
1591 void setZExt() { Flags |= One << ZExtOffs; }
1592
1593 bool isSExt() const { return Flags & SExt; }
1594 void setSExt() { Flags |= One << SExtOffs; }
1595
1596 bool isInReg() const { return Flags & InReg; }
1597 void setInReg() { Flags |= One << InRegOffs; }
1598
1599 bool isSRet() const { return Flags & SRet; }
1600 void setSRet() { Flags |= One << SRetOffs; }
1601
1602 bool isByVal() const { return Flags & ByVal; }
1603 void setByVal() { Flags |= One << ByValOffs; }
1604
1605 bool isNest() const { return Flags & Nest; }
1606 void setNest() { Flags |= One << NestOffs; }
1607
1608 unsigned getByValAlign() const {
1609 return (One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2;
1610 }
1611 void setByValAlign(unsigned A) {
1612 Flags = (Flags & ~ByValAlign) |
1613 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
1614 }
1615
1616 unsigned getOrigAlign() const {
1617 return (One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2;
1618 }
1619 void setOrigAlign(unsigned A) {
1620 Flags = (Flags & ~OrigAlign) |
1621 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
1622 }
1623
1624 unsigned getByValSize() const {
1625 return (Flags & ByValSize) >> ByValSizeOffs;
1626 }
1627 void setByValSize(unsigned S) {
1628 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
1629 }
1630
1631 /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
1632 std::string getArgFlagsString();
1633
1634 /// getRawBits - Represent the flags as a bunch of bits.
1635 uint64_t getRawBits() const { return Flags; }
1636 };
1637 }
1638
1639 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
1640 class ARG_FLAGSSDNode : public SDNode {
1641 ISD::ArgFlagsTy TheFlags;
1642 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1643 protected:
1644 friend class SelectionDAG;
1645 explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
1646 : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
1647 }
1648 public:
1649 ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
1650
1651 static bool classof(const ARG_FLAGSSDNode *) { return true; }
1652 static bool classof(const SDNode *N) {
1653 return N->getOpcode() == ISD::ARG_FLAGS;
1654 }
1655 };
1656
15861657 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
15871658 /// to parameterize some operations.
15881659 class VTSDNode : public SDNode {
3434 void CCState::HandleByVal(unsigned ValNo, MVT::ValueType ValVT,
3535 MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,
3636 int MinSize, int MinAlign,
37 ISD::ParamFlags::ParamFlagsTy ArgFlags) {
38 unsigned Align = 1 << ((ArgFlags & ISD::ParamFlags::ByValAlign) >>
39 ISD::ParamFlags::ByValAlignOffs);
40 unsigned Size = (ArgFlags & ISD::ParamFlags::ByValSize) >>
41 ISD::ParamFlags::ByValSizeOffs;
37 ISD::ArgFlagsTy ArgFlags) {
38 unsigned Align = ArgFlags.getByValAlign();
39 unsigned Size = ArgFlags.getByValSize();
4240 if (MinSize > (int)Size)
4341 Size = MinSize;
4442 if (MinAlign > (int)Align)
6462
6563 for (unsigned i = 0; i != NumArgs; ++i) {
6664 MVT::ValueType ArgVT = TheArgs->getValueType(i);
67 SDOperand FlagOp = TheArgs->getOperand(3+i);
68 ISD::ParamFlags::ParamFlagsTy ArgFlags =
69 cast(FlagOp)->getValue();
65 ISD::ArgFlagsTy ArgFlags =
66 cast(TheArgs->getOperand(3+i))->getArgFlags();
7067 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
7168 cerr << "Formal argument #" << i << " has unhandled type "
7269 << MVT::getValueTypeString(ArgVT) << "\n";
8178 // Determine which register each value should be copied into.
8279 for (unsigned i = 0, e = TheRet->getNumOperands() / 2; i != e; ++i) {
8380 MVT::ValueType VT = TheRet->getOperand(i*2+1).getValueType();
84 if (Fn(i, VT, VT, CCValAssign::Full,
85 cast(TheRet->getOperand(i*2+2))->getValue(), *this)){
81 ISD::ArgFlagsTy ArgFlags =
82 cast(TheRet->getOperand(i*2+2))->getArgFlags();
83 if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, *this)){
8684 cerr << "Return operand #" << i << " has unhandled type "
8785 << MVT::getValueTypeString(VT) << "\n";
8886 abort();
9795 unsigned NumOps = (TheCall->getNumOperands() - 5) / 2;
9896 for (unsigned i = 0; i != NumOps; ++i) {
9997 MVT::ValueType ArgVT = TheCall->getOperand(5+2*i).getValueType();
100 SDOperand FlagOp = TheCall->getOperand(5+2*i+1);
101 ISD::ParamFlags::ParamFlagsTy ArgFlags =
102 cast(FlagOp)->getValue();
98 ISD::ArgFlagsTy ArgFlags =
99 cast(TheCall->getOperand(5+2*i+1))->getArgFlags();
103100 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
104101 cerr << "Call operand #" << i << " has unhandled type "
105102 << MVT::getValueTypeString(ArgVT) << "\n";
113110 void CCState::AnalyzeCallResult(SDNode *TheCall, CCAssignFn Fn) {
114111 for (unsigned i = 0, e = TheCall->getNumValues() - 1; i != e; ++i) {
115112 MVT::ValueType VT = TheCall->getValueType(i);
116 if (Fn(i, VT, VT, CCValAssign::Full, 0, *this)) {
113 if (Fn(i, VT, VT, CCValAssign::Full, ISD::ArgFlagsTy(), *this)) {
117114 cerr << "Call result #" << i << " has unhandled type "
118115 << MVT::getValueTypeString(VT) << "\n";
119116 abort();
807807 case ISD::MEMOPERAND:
808808 case ISD::STRING:
809809 case ISD::CONDCODE:
810 case ISD::ARG_FLAGS:
810811 // Primitives must all be legal.
811812 assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) &&
812813 "This must be legal!");
354354 // Handle SDNode leafs with special info.
355355 switch (N->getOpcode()) {
356356 default: break; // Normal nodes don't need extra info.
357 case ISD::ARG_FLAGS:
358 ID.AddInteger(cast(N)->getArgFlags().getRawBits());
359 break;
357360 case ISD::TargetConstant:
358361 case ISD::Constant:
359362 ID.Add(cast(N)->getAPIntValue());
917920 if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
918921 return SDOperand(E, 0);
919922 SDNode *N = new BasicBlockSDNode(MBB);
923 CSEMap.InsertNode(N, IP);
924 AllNodes.push_back(N);
925 return SDOperand(N, 0);
926 }
927
928 SDOperand SelectionDAG::getArgFlags(ISD::ArgFlagsTy Flags) {
929 FoldingSetNodeID ID;
930 AddNodeIDNode(ID, ISD::ARG_FLAGS, getVTList(MVT::Other), 0, 0);
931 ID.AddInteger(Flags.getRawBits());
932 void *IP = 0;
933 if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
934 return SDOperand(E, 0);
935 SDNode *N = new ARG_FLAGSSDNode(Flags);
920936 CSEMap.InsertNode(N, IP);
921937 AllNodes.push_back(N);
922938 return SDOperand(N, 0);
35833599 void RegisterSDNode::ANCHOR() {}
35843600 void ExternalSymbolSDNode::ANCHOR() {}
35853601 void CondCodeSDNode::ANCHOR() {}
3602 void ARG_FLAGSSDNode::ANCHOR() {}
35863603 void VTSDNode::ANCHOR() {}
35873604 void LoadSDNode::ANCHOR() {}
35883605 void StoreSDNode::ANCHOR() {}
38303847
38313848 case ISD::STRING: return "String";
38323849 case ISD::BasicBlock: return "BasicBlock";
3850 case ISD::ARG_FLAGS: return "ArgFlags";
38333851 case ISD::VALUETYPE: return "ValueType";
38343852 case ISD::Register: return "Register";
38353853
40404058 case ISD::POST_DEC:
40414059 return "";
40424060 }
4061 }
4062
4063 std::string ISD::ArgFlagsTy::getArgFlagsString() {
4064 std::string S = "< ";
4065
4066 if (isZExt())
4067 S += "zext ";
4068 if (isSExt())
4069 S += "sext ";
4070 if (isInReg())
4071 S += "inreg ";
4072 if (isSRet())
4073 S += "sret ";
4074 if (isByVal())
4075 S += "byval ";
4076 if (isNest())
4077 S += "nest ";
4078 if (getByValAlign())
4079 S += "byval-align:" + utostr(getByValAlign()) + " ";
4080 if (getOrigAlign())
4081 S += "orig-align:" + utostr(getOrigAlign()) + " ";
4082 if (getByValSize())
4083 S += "byval-size:" + utostr(getByValSize()) + " ";
4084 return S + ">";
40434085 }
40444086
40454087 void SDNode::dump() const { dump(0); }
41374179 cerr << "<" << M->MO.getValue() << ":" << M->MO.getOffset() << ">";
41384180 else
41394181 cerr << "MO.getOffset() << ">";
4182 } else if (const ARG_FLAGSSDNode *N = dyn_cast(this)) {
4183 cerr << N->getArgFlags().getArgFlagsString();
41404184 } else if (const VTSDNode *N = dyn_cast(this)) {
41414185 cerr << ":" << MVT::getValueTypeString(N->getVT());
41424186 } else if (const LoadSDNode *LD = dyn_cast(this)) {
10631063
10641064 for (unsigned i = 0; i < NumParts; ++i) {
10651065 NewValues.push_back(Parts[i]);
1066 NewValues.push_back(DAG.getConstant(false, MVT::i32));
1066 NewValues.push_back(DAG.getArgFlags(ISD::ArgFlagsTy()));
10671067 }
10681068 }
10691069 DAG.setRoot(DAG.getNode(ISD::RET, MVT::Other,
40644064 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end();
40654065 I != E; ++I, ++j) {
40664066 MVT::ValueType VT = getValueType(I->getType());
4067 ISD::ParamFlags::ParamFlagsTy Flags = ISD::ParamFlags::NoFlagSet;
4067 ISD::ArgFlagsTy Flags;
40684068 unsigned OriginalAlignment =
40694069 getTargetData()->getABITypeAlignment(I->getType());
40704070
4071 // FIXME: Distinguish between a formal with no [sz]ext attribute from one
4072 // that is zero extended!
40734071 if (F.paramHasAttr(j, ParamAttr::ZExt))
4074 Flags &= ~(ISD::ParamFlags::SExt);
4072 Flags.setZExt();
40754073 if (F.paramHasAttr(j, ParamAttr::SExt))
4076 Flags |= ISD::ParamFlags::SExt;
4074 Flags.setSExt();
40774075 if (F.paramHasAttr(j, ParamAttr::InReg))
4078 Flags |= ISD::ParamFlags::InReg;
4076 Flags.setInReg();
40794077 if (F.paramHasAttr(j, ParamAttr::StructRet))
4080 Flags |= ISD::ParamFlags::StructReturn;
4078 Flags.setSRet();
40814079 if (F.paramHasAttr(j, ParamAttr::ByVal)) {
4082 Flags |= ISD::ParamFlags::ByVal;
4080 Flags.setByVal();
40834081 const PointerType *Ty = cast(I->getType());
40844082 const Type *ElementTy = Ty->getElementType();
4085 unsigned FrameAlign = Log2_32(getByValTypeAlignment(ElementTy));
4083 unsigned FrameAlign = getByValTypeAlignment(ElementTy);
40864084 unsigned FrameSize = getTargetData()->getABITypeSize(ElementTy);
40874085 // For ByVal, alignment should be passed from FE. BE will guess if
40884086 // this info is not there but there are cases it cannot get right.
40894087 if (F.getParamAlignment(j))
4090 FrameAlign = Log2_32(F.getParamAlignment(j));
4091 Flags |= ((ISD::ParamFlags::ParamFlagsTy)FrameAlign
4092 << ISD::ParamFlags::ByValAlignOffs);
4093 Flags |= ((ISD::ParamFlags::ParamFlagsTy)FrameSize
4094 << ISD::ParamFlags::ByValSizeOffs);
4088 FrameAlign = F.getParamAlignment(j);
4089 Flags.setByValAlign(FrameAlign);
4090 Flags.setByValSize(FrameSize);
40954091 }
40964092 if (F.paramHasAttr(j, ParamAttr::Nest))
4097 Flags |= ISD::ParamFlags::Nest;
4098 Flags |= ((ISD::ParamFlags::ParamFlagsTy)OriginalAlignment
4099 << ISD::ParamFlags::OrigAlignmentOffs);
4093 Flags.setNest();
4094 Flags.setOrigAlign(OriginalAlignment);
41004095
41014096 MVT::ValueType RegisterVT = getRegisterType(VT);
41024097 unsigned NumRegs = getNumRegisters(VT);
41044099 RetVals.push_back(RegisterVT);
41054100 // if it isn't first piece, alignment must be 1
41064101 if (i > 0)
4107 Flags = (Flags & (~ISD::ParamFlags::OrigAlignment)) |
4108 (ISD::ParamFlags::One << ISD::ParamFlags::OrigAlignmentOffs);
4109 Ops.push_back(DAG.getConstant(Flags, MVT::i64));
4102 Flags.setOrigAlign(1);
4103 Ops.push_back(DAG.getArgFlags(Flags));
41104104 }
41114105 }
41124106
41824176 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
41834177 MVT::ValueType VT = getValueType(Args[i].Ty);
41844178 SDOperand Op = Args[i].Node;
4185 ISD::ParamFlags::ParamFlagsTy Flags = ISD::ParamFlags::NoFlagSet;
4179 ISD::ArgFlagsTy Flags;
41864180 unsigned OriginalAlignment =
41874181 getTargetData()->getABITypeAlignment(Args[i].Ty);
4188
4182
4183 if (Args[i].isZExt)
4184 Flags.setZExt();
41894185 if (Args[i].isSExt)
4190 Flags |= ISD::ParamFlags::SExt;
4191 if (Args[i].isZExt)
4192 Flags |= ISD::ParamFlags::ZExt;
4186 Flags.setSExt();
41934187 if (Args[i].isInReg)
4194 Flags |= ISD::ParamFlags::InReg;
4188 Flags.setInReg();
41954189 if (Args[i].isSRet)
4196 Flags |= ISD::ParamFlags::StructReturn;
4190 Flags.setSRet();
41974191 if (Args[i].isByVal) {
4198 Flags |= ISD::ParamFlags::ByVal;
4192 Flags.setByVal();
41994193 const PointerType *Ty = cast(Args[i].Ty);
42004194 const Type *ElementTy = Ty->getElementType();
4201 unsigned FrameAlign = Log2_32(getByValTypeAlignment(ElementTy));
4195 unsigned FrameAlign = getByValTypeAlignment(ElementTy);
42024196 unsigned FrameSize = getTargetData()->getABITypeSize(ElementTy);
42034197 // For ByVal, alignment should come from FE. BE will guess if this
42044198 // info is not there but there are cases it cannot get right.
42054199 if (Args[i].Alignment)
4206 FrameAlign = Log2_32(Args[i].Alignment);
4207 Flags |= ((ISD::ParamFlags::ParamFlagsTy)FrameAlign
4208 << ISD::ParamFlags::ByValAlignOffs);
4209 Flags |= ((ISD::ParamFlags::ParamFlagsTy)FrameSize
4210 << ISD::ParamFlags::ByValSizeOffs);
4200 FrameAlign = Args[i].Alignment;
4201 Flags.setByValAlign(FrameAlign);
4202 Flags.setByValSize(FrameSize);
42114203 }
42124204 if (Args[i].isNest)
4213 Flags |= ISD::ParamFlags::Nest;
4214 Flags |= ((ISD::ParamFlags::ParamFlagsTy)OriginalAlignment)
4215 << ISD::ParamFlags::OrigAlignmentOffs;
4205 Flags.setNest();
4206 Flags.setOrigAlign(OriginalAlignment);
42164207
42174208 MVT::ValueType PartVT = getRegisterType(VT);
42184209 unsigned NumParts = getNumRegisters(VT);
42284219
42294220 for (unsigned i = 0; i != NumParts; ++i) {
42304221 // if it isn't first piece, alignment must be 1
4231 ISD::ParamFlags::ParamFlagsTy MyFlags = Flags;
4222 ISD::ArgFlagsTy MyFlags = Flags;
42324223 if (i != 0)
4233 MyFlags = (MyFlags & (~ISD::ParamFlags::OrigAlignment)) |
4234 (ISD::ParamFlags::One << ISD::ParamFlags::OrigAlignmentOffs);
4224 MyFlags.setOrigAlign(1);
42354225
42364226 Ops.push_back(Parts[i]);
4237 Ops.push_back(DAG.getConstant(MyFlags, MVT::i64));
4227 Ops.push_back(DAG.getArgFlags(MyFlags));
42384228 }
42394229 }
42404230
150150 Op += "<" + M->MO.getValue()->getName() + ":" + itostr(M->MO.getOffset()) + ">";
151151 else
152152 Op += "MO.getOffset()) + ">";
153 } else if (const ARG_FLAGSSDNode *N = dyn_cast(Node)) {
154 Op = Op + " AF=" + N->getArgFlags().getArgFlagsString();
153155 } else if (const VTSDNode *N = dyn_cast(Node)) {
154156 Op = Op + " VT=" + MVT::getValueTypeString(N->getVT());
155157 } else if (const StringSDNode *N = dyn_cast(Node)) {
366366 HowToPassArgument(MVT::ValueType ObjectVT, unsigned NumGPRs,
367367 unsigned StackOffset, unsigned &NeededGPRs,
368368 unsigned &NeededStackSize, unsigned &GPRPad,
369 unsigned &StackPad, ISD::ParamFlags::ParamFlagsTy Flags) {
369 unsigned &StackPad, ISD::ArgFlagsTy Flags) {
370370 NeededStackSize = 0;
371371 NeededGPRs = 0;
372372 StackPad = 0;
373373 GPRPad = 0;
374 unsigned align = ((Flags & ISD::ParamFlags::OrigAlignment)
375 >> ISD::ParamFlags::OrigAlignmentOffs);
374 unsigned align = Flags.getOrigAlign();
376375 GPRPad = NumGPRs % ((align + 3)/4);
377376 StackPad = StackOffset % align;
378377 unsigned firstGPR = NumGPRs + GPRPad;
421420 unsigned StackPad;
422421 unsigned GPRPad;
423422 MVT::ValueType ObjectVT = Op.getOperand(5+2*i).getValueType();
424 ISD::ParamFlags::ParamFlagsTy Flags = Op.getConstantOperandVal(5+2*i+1);
423 ISD::ArgFlagsTy Flags =
424 cast(Op.getOperand(5+2*i+1))->getArgFlags();
425425 HowToPassArgument(ObjectVT, NumGPRs, NumBytes, ObjGPRs, ObjSize,
426426 GPRPad, StackPad, Flags);
427427 NumBytes += ObjSize + StackPad;
444444 std::vector MemOpChains;
445445 for (unsigned i = 0; i != NumOps; ++i) {
446446 SDOperand Arg = Op.getOperand(5+2*i);
447 ISD::ParamFlags::ParamFlagsTy Flags = Op.getConstantOperandVal(5+2*i+1);
447 ISD::ArgFlagsTy Flags =
448 cast(Op.getOperand(5+2*i+1))->getArgFlags();
448449 MVT::ValueType ArgVT = Arg.getValueType();
449450
450451 unsigned ObjSize;
923924 unsigned ObjGPRs;
924925 unsigned GPRPad;
925926 unsigned StackPad;
926 ISD::ParamFlags::ParamFlagsTy Flags = Op.getConstantOperandVal(ArgNo + 3);
927 ISD::ArgFlagsTy Flags =
928 cast(Op.getOperand(ArgNo + 3))->getArgFlags();
927929 HowToPassArgument(ObjectVT, NumGPRs, ArgOffset, ObjGPRs,
928930 ObjSize, GPRPad, StackPad, Flags);
929931 NumGPRs += GPRPad;
13651365 ++ArgNo) {
13661366 MVT::ValueType ObjectVT = Op.getValue(ArgNo).getValueType();
13671367 unsigned ObjSize = MVT::getSizeInBits(ObjectVT)/8;
1368 ISD::ParamFlags::ParamFlagsTy Flags =
1369 cast(Op.getOperand(ArgNo+3))->getValue();
1370 unsigned isByVal = Flags & ISD::ParamFlags::ByVal;
1371
1372 if (isByVal) {
1368 ISD::ArgFlagsTy Flags =
1369 cast(Op.getOperand(ArgNo+3))->getArgFlags();
1370
1371 if (Flags.isByVal()) {
13731372 // ObjSize is the true size, ArgSize rounded up to multiple of regs.
1374 ObjSize = (Flags & ISD::ParamFlags::ByValSize) >>
1375 ISD::ParamFlags::ByValSizeOffs;
1373 ObjSize = Flags.getByValSize();
13761374 unsigned ArgSize =
13771375 ((ObjSize + PtrByteSize - 1)/PtrByteSize) * PtrByteSize;
13781376 VecArgOffset += ArgSize;
14091407 //
14101408 // In the ELF 32 ABI, GPRs and stack are double word align: an argument
14111409 // represented with two words (long long or double) must be copied to an
1412 // even GPR_idx value or to an even ArgOffset value.
1410 // even GPR_idx value or to an even ArgOffset value. TODO: implement this.
14131411
14141412 SmallVector MemOps;
14151413
14191417 MVT::ValueType ObjectVT = Op.getValue(ArgNo).getValueType();
14201418 unsigned ObjSize = MVT::getSizeInBits(ObjectVT)/8;
14211419 unsigned ArgSize = ObjSize;
1422 ISD::ParamFlags::ParamFlagsTy Flags =
1423 cast(Op.getOperand(ArgNo+3))->getValue();
1424 unsigned AlignFlag = ISD::ParamFlags::One
1425 << ISD::ParamFlags::OrigAlignmentOffs;
1426 unsigned isByVal = Flags & ISD::ParamFlags::ByVal;
1420 ISD::ArgFlagsTy Flags =
1421 cast(Op.getOperand(ArgNo+3))->getArgFlags();
14271422 // See if next argument requires stack alignment in ELF
1428 bool Expand = (ObjectVT == MVT::f64) || ((ArgNo + 1 < e) &&
1429 (cast(Op.getOperand(ArgNo+4))->getValue() & AlignFlag) &&
1430 (!(Flags & AlignFlag)));
1423 bool Expand = false; // TODO: implement this.
14311424
14321425 unsigned CurArgOffset = ArgOffset;
14331426
14341427 // FIXME alignment for ELF may not be right
14351428 // FIXME the codegen can be much improved in some cases.
14361429 // We do not have to keep everything in memory.
1437 if (isByVal) {
1430 if (Flags.isByVal()) {
14381431 // ObjSize is the true size, ArgSize rounded up to multiple of registers.
1439 ObjSize = (Flags & ISD::ParamFlags::ByValSize) >>
1440 ISD::ParamFlags::ByValSizeOffs;
1432 ObjSize = Flags.getByValSize();
14411433 ArgSize = ((ObjSize + PtrByteSize - 1)/PtrByteSize) * PtrByteSize;
14421434 // Double word align in ELF
14431435 if (Expand && isELF32_ABI) GPR_idx += (GPR_idx % 2);
15201512 if (ObjectVT == MVT::i32) {
15211513 // PPC64 passes i8, i16, and i32 values in i64 registers. Promote
15221514 // value to MVT::i64 and then truncate to the correct register size.
1523 if (Flags & ISD::ParamFlags::SExt)
1515 if (Flags.isSExt())
15241516 ArgVal = DAG.getNode(ISD::AssertSext, MVT::i64, ArgVal,
15251517 DAG.getValueType(ObjectVT));
1526 else if (Flags & ISD::ParamFlags::ZExt)
1518 else if (Flags.isZExt())
15271519 ArgVal = DAG.getNode(ISD::AssertZext, MVT::i64, ArgVal,
15281520 DAG.getValueType(ObjectVT));
15291521
17351727 /// does not fit in registers.
17361728 static SDOperand
17371729 CreateCopyOfByValArgument(SDOperand Src, SDOperand Dst, SDOperand Chain,
1738 ISD::ParamFlags::ParamFlagsTy Flags,
1739 SelectionDAG &DAG, unsigned Size) {
1740 unsigned Align = ISD::ParamFlags::One <<
1741 ((Flags & ISD::ParamFlags::ByValAlign) >> ISD::ParamFlags::ByValAlignOffs);
1742 SDOperand AlignNode = DAG.getConstant(Align, MVT::i32);
1730 ISD::ArgFlagsTy Flags, SelectionDAG &DAG,
1731 unsigned Size) {
1732 SDOperand AlignNode = DAG.getConstant(Flags.getByValAlign(), MVT::i32);
17431733 SDOperand SizeNode = DAG.getConstant(Size, MVT::i32);
17441734 SDOperand AlwaysInline = DAG.getConstant(0, MVT::i32);
17451735 return DAG.getMemcpy(Chain, Dst, Src, SizeNode, AlignNode, AlwaysInline);
17911781 NumBytes = ((NumBytes+15)/16)*16;
17921782 }
17931783 }
1794 ISD::ParamFlags::ParamFlagsTy Flags =
1795 cast(Op.getOperand(5+2*i+1))->getValue();
1784 ISD::ArgFlagsTy Flags =
1785 cast(Op.getOperand(5+2*i+1))->getArgFlags();
17961786 unsigned ArgSize =MVT::getSizeInBits(Op.getOperand(5+2*i).getValueType())/8;
1797 if (Flags & ISD::ParamFlags::ByVal)
1798 ArgSize = (Flags & ISD::ParamFlags::ByValSize) >>
1799 ISD::ParamFlags::ByValSizeOffs;
1787 if (Flags.isByVal())
1788 ArgSize = Flags.getByValSize();
18001789 ArgSize = ((ArgSize + PtrByteSize - 1)/PtrByteSize) * PtrByteSize;
18011790 NumBytes += ArgSize;
18021791 }
18611850 for (unsigned i = 0; i != NumOps; ++i) {
18621851 bool inMem = false;
18631852 SDOperand Arg = Op.getOperand(5+2*i);
1864 ISD::ParamFlags::ParamFlagsTy Flags =
1865 cast(Op.getOperand(5+2*i+1))->getValue();
1866 unsigned AlignFlag = ISD::ParamFlags::One <<
1867 ISD::ParamFlags::OrigAlignmentOffs;
1853 ISD::ArgFlagsTy Flags =
1854 cast(Op.getOperand(5+2*i+1))->getArgFlags();
18681855 // See if next argument requires stack alignment in ELF
1869 unsigned next = 5+2*(i+1)+1;
1870 bool Expand = (Arg.getValueType() == MVT::f64) || ((i + 1 < NumOps) &&
1871 (cast(Op.getOperand(next))->getValue() & AlignFlag) &&
1872 (!(Flags & AlignFlag)));
1856 bool Expand = false; // TODO: implement this.
18731857
18741858 // PtrOff will be used to store the current argument to the stack if a
18751859 // register cannot be found for it.
18861870
18871871 // On PPC64, promote integers to 64-bit values.
18881872 if (isPPC64 && Arg.getValueType() == MVT::i32) {
1889 unsigned ExtOp = (Flags & 1) ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND;
1873 // FIXME: Should this use ANY_EXTEND if neither sext nor zext?
1874 unsigned ExtOp = Flags.isSExt() ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND;
18901875 Arg = DAG.getNode(ExtOp, MVT::i64, Arg);
18911876 }
18921877
18931878 // FIXME Elf untested, what are alignment rules?
18941879 // FIXME memcpy is used way more than necessary. Correctness first.
1895 if (Flags & ISD::ParamFlags::ByVal) {
1896 unsigned Size = (Flags & ISD::ParamFlags::ByValSize) >>
1897 ISD::ParamFlags::ByValSizeOffs;
1880 if (Flags.isByVal()) {
1881 unsigned Size = Flags.getByValSize();
18981882 if (isELF32_ABI && Expand) GPR_idx += (GPR_idx % 2);
18991883 if (Size==1 || Size==2) {
19001884 // Very small objects are passed right-justified.
3333
3434 /// CCIfByVal - If the current argument has ByVal parameter attribute, apply
3535 /// Action A.
36 class CCIfByVal : CCIf<"ArgFlags & ISD::ParamFlags::ByVal", A> {
36 class CCIfByVal : CCIf<"ArgFlags.isByVal()", A> {
3737 }
3838
3939 /// CCIfCC - Match of the current calling convention is 'CC'.
4242
4343 /// CCIfInReg - If this argument is marked with the 'inreg' attribute, apply
4444 /// the specified action.
45 class CCIfInReg : CCIf<"ArgFlags & ISD::ParamFlags::InReg", A> {}
45 class CCIfInReg : CCIf<"ArgFlags.isInReg()", A> {}
4646
4747 /// CCIfNest - If this argument is marked with the 'nest' attribute, apply
4848 /// the specified action.
49 class CCIfNest : CCIf<"ArgFlags & ISD::ParamFlags::Nest", A> {}
49 class CCIfNest : CCIf<"ArgFlags.isNest()", A> {}
5050
5151 /// CCIfNotVarArg - If the current function is not vararg - apply the action
5252 class CCIfNotVarArg : CCIf<"!State.isVarArg()", A> {}
968968 unsigned NumOps = (Op.getNumOperands() - 5) / 2;
969969 if (!NumOps)
970970 return false;
971
972 ConstantSDNode *Flags = cast(Op.getOperand(6));
973 return Flags->getValue() & ISD::ParamFlags::StructReturn;
971
972 return cast(Op.getOperand(6))->getArgFlags().isSRet();
974973 }
975974
976975 /// ArgsAreStructReturn - Determines whether a FORMAL_ARGUMENTS node uses struct
979978 unsigned NumArgs = Op.Val->getNumValues() - 1;
980979 if (!NumArgs)
981980 return false;
982
983 ConstantSDNode *Flags = cast(Op.getOperand(3));
984 return Flags->getValue() & ISD::ParamFlags::StructReturn;
981
982 return cast(Op.getOperand(3))->getArgFlags().isSRet();
985983 }
986984
987985 /// IsCalleePop - Determines whether a CALL or FORMAL_ARGUMENTS node requires the
11091107 /// parameter.
11101108 static SDOperand
11111109 CreateCopyOfByValArgument(SDOperand Src, SDOperand Dst, SDOperand Chain,
1112 ISD::ParamFlags::ParamFlagsTy Flags,
1113 SelectionDAG &DAG) {
1114 unsigned Align = ISD::ParamFlags::One <<
1115 ((Flags & ISD::ParamFlags::ByValAlign) >> ISD::ParamFlags::ByValAlignOffs);
1116 unsigned Size = (Flags & ISD::ParamFlags::ByValSize) >>
1117 ISD::ParamFlags::ByValSizeOffs;
1118 SDOperand AlignNode = DAG.getConstant(Align, MVT::i32);
1119 SDOperand SizeNode = DAG.getConstant(Size, MVT::i32);
1110 ISD::ArgFlagsTy Flags, SelectionDAG &DAG) {
1111 SDOperand AlignNode = DAG.getConstant(Flags.getByValAlign(), MVT::i32);
1112 SDOperand SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32);
11201113 SDOperand AlwaysInline = DAG.getConstant(1, MVT::i32);
11211114 return DAG.getMemcpy(Chain, Dst, Src, SizeNode, AlignNode, AlwaysInline);
11221115 }
11271120 unsigned CC,
11281121 SDOperand Root, unsigned i) {
11291122 // Create the nodes corresponding to a load from this parameter slot.
1130 ISD::ParamFlags::ParamFlagsTy Flags =
1131 cast(Op.getOperand(3 + i))->getValue();
1123 ISD::ArgFlagsTy Flags =
1124 cast(Op.getOperand(3 + i))->getArgFlags();
11321125 bool AlwaysUseMutable = (CC==CallingConv::Fast) && PerformTailCallOpt;
1133 bool isByVal = Flags & ISD::ParamFlags::ByVal;
1134 bool isImmutable = !AlwaysUseMutable && !isByVal;
1126 bool isImmutable = !AlwaysUseMutable && !Flags.isByVal();
11351127
11361128 // FIXME: For now, all byval parameter objects are marked mutable. This can be
11371129 // changed with more analysis.
11401132 int FI = MFI->CreateFixedObject(MVT::getSizeInBits(VA.getValVT())/8,
11411133 VA.getLocMemOffset(), isImmutable);
11421134 SDOperand FIN = DAG.getFrameIndex(FI, getPointerTy());
1143 if (isByVal)
1135 if (Flags.isByVal())
11441136 return FIN;
11451137 return DAG.getLoad(VA.getValVT(), Root, FIN,
11461138 PseudoSourceValue::getFixedStack(), FI);
13451337 unsigned LocMemOffset = VA.getLocMemOffset();
13461338 SDOperand PtrOff = DAG.getIntPtrConstant(LocMemOffset);
13471339 PtrOff = DAG.getNode(ISD::ADD, getPointerTy(), StackPtr, PtrOff);
1348 SDOperand FlagsOp = Op.getOperand(6+2*VA.getValNo());
1349 ISD::ParamFlags::ParamFlagsTy Flags =
1350 cast(FlagsOp)->getValue();
1351 if (Flags & ISD::ParamFlags::ByVal) {
1340 ISD::ArgFlagsTy Flags =
1341 cast(Op.getOperand(6+2*VA.getValNo()))->getArgFlags();
1342 if (Flags.isByVal()) {
13521343 return CreateCopyOfByValArgument(Arg, PtrOff, Chain, Flags, DAG);
13531344 }
13541345 return DAG.getStore(Chain, Arg, PtrOff,
15351526 assert(VA.isMemLoc());
15361527 SDOperand Arg = Op.getOperand(5+2*VA.getValNo());
15371528 SDOperand FlagsOp = Op.getOperand(6+2*VA.getValNo());
1538 ISD::ParamFlags::ParamFlagsTy Flags =
1539 cast(FlagsOp)->getValue();
1529 ISD::ArgFlagsTy Flags =
1530 cast(FlagsOp)->getArgFlags();
15401531 // Create frame index.
15411532 int32_t Offset = VA.getLocMemOffset()+FPDiff;
15421533 uint32_t OpSize = (MVT::getSizeInBits(VA.getLocVT())+7)/8;
15531544 }
15541545 assert(IsPossiblyOverwrittenArgumentOfTailCall(Arg, MFI)==false ||
15551546 (Found==true && "No corresponding Argument was found"));
1556
1557 if (Flags & ISD::ParamFlags::ByVal) {
1547
1548 if (Flags.isByVal()) {
15581549 // Copy relative to framepointer.
15591550 MemOpChains2.push_back(CreateCopyOfByValArgument(Arg, FIN, Chain,
15601551 Flags, DAG));
2929 << std::string(CCs[i]->getName().size()+13, ' ')
3030 << "MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,\n"
3131 << std::string(CCs[i]->getName().size()+13, ' ')
32 << "ISD::ParamFlags::ParamFlagsTy ArgFlags, CCState &State);\n";
32 << "ISD::ArgFlagsTy ArgFlags, CCState &State);\n";
3333 }
3434
3535 // Emit each calling convention description in full.
4747 << std::string(CC->getName().size()+13, ' ')
4848 << "MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,\n"
4949 << std::string(CC->getName().size()+13, ' ')
50 << "ISD::ParamFlags::ParamFlagsTy ArgFlags, CCState &State) {\n";
50 << "ISD::ArgFlagsTy ArgFlags, CCState &State) {\n";
5151 // Emit all of the actions, in order.
5252 for (unsigned i = 0, e = CCActions->getSize(); i != e; ++i) {
5353 O << "\n";
133133 } else if (Action->isSubClassOf("CCPromoteToType")) {
134134 Record *DestTy = Action->getValueAsDef("DestTy");
135135 O << IndentStr << "LocVT = " << getEnumName(getValueType(DestTy)) <<";\n";
136 O << IndentStr << "if (ArgFlags & ISD::ParamFlags::SExt)\n"
136 O << IndentStr << "if (ArgFlags.isSExt())\n"
137137 << IndentStr << IndentStr << "LocInfo = CCValAssign::SExt;\n"
138 << IndentStr << "else if (ArgFlags & ISD::ParamFlags::ZExt)\n"
138 << IndentStr << "else if (ArgFlags.isZExt())\n"
139139 << IndentStr << IndentStr << "LocInfo = CCValAssign::ZExt;\n"
140140 << IndentStr << "else\n"
141141 << IndentStr << IndentStr << "LocInfo = CCValAssign::AExt;\n";