llvm.org GIT mirror llvm / b8cafe3
Increase ISD::ParamFlags to 64 bits. Increase the ByValSize field to 32 bits, thus enabling correct handling of ByVal structs bigger than 0x1ffff. Abstract interface a bit. Fixes gcc.c-torture/execute/pr23135.c and gcc.c-torture/execute/pr28982b.c in gcc testsuite (were ICE'ing on ppc32, quietly producing wrong code on x86-32.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48122 91177308-0d34-0410-b5e6-96231b3b80d8 Dale Johannesen 12 years ago
8 changed file(s) with 81 addition(s) and 58 deletion(s). Raw diff Collapse all Expand all
1616
1717 #include "llvm/ADT/SmallVector.h"
1818 #include "llvm/CodeGen/ValueTypes.h"
19 #include "llvm/CodeGen/SelectionDAGNodes.h"
1920
2021 namespace llvm {
2122 class TargetRegisterInfo;
9697 /// reflect the change.
9798 typedef bool CCAssignFn(unsigned ValNo, MVT::ValueType ValVT,
9899 MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,
99 unsigned ArgFlags, CCState &State);
100 ISD::ParamFlags::ParamFlagsTy ArgFlags, CCState &State);
100101
101102
102103 /// CCState - This class holds information needed while lowering arguments and
195196 // parameter attribute.
196197 void HandleByVal(unsigned ValNo, MVT::ValueType ValVT,
197198 MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,
198 int MinSize, int MinAlign, unsigned ArgFlags);
199 int MinSize, int MinAlign,
200 ISD::ParamFlags::ParamFlagsTy ArgFlags);
199201
200202 private:
201203 /// MarkAllocated - Mark a register and all of its aliases as allocated.
5656 ///
5757 namespace ISD {
5858 namespace ParamFlags {
59 enum Flags {
60 NoFlagSet = 0,
61 ZExt = 1<<0, ///< Parameter should be zero extended
62 ZExtOffs = 0,
63 SExt = 1<<1, ///< Parameter should be sign extended
64 SExtOffs = 1,
65 InReg = 1<<2, ///< Parameter should be passed in register
66 InRegOffs = 2,
67 StructReturn = 1<<3, ///< Hidden struct-return pointer
68 StructReturnOffs = 3,
69 ByVal = 1<<4, ///< Struct passed by value
70 ByValOffs = 4,
71 Nest = 1<<5, ///< Parameter is nested function static chain
72 NestOffs = 5,
73 ByValAlign = 0xF << 6, //< The alignment of the struct
74 ByValAlignOffs = 6,
75 ByValSize = 0x1ffff << 10, //< The size of the struct
76 ByValSizeOffs = 10,
77 OrigAlignment = 0x1F<<27,
78 OrigAlignmentOffs = 27
79 };
59 typedef unsigned long long 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
8082 }
8183
8284 //===--------------------------------------------------------------------===//
3434 void CCState::HandleByVal(unsigned ValNo, MVT::ValueType ValVT,
3535 MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,
3636 int MinSize, int MinAlign,
37 unsigned ArgFlags) {
37 ISD::ParamFlags::ParamFlagsTy ArgFlags) {
3838 unsigned Align = 1 << ((ArgFlags & ISD::ParamFlags::ByValAlign) >>
3939 ISD::ParamFlags::ByValAlignOffs);
4040 unsigned Size = (ArgFlags & ISD::ParamFlags::ByValSize) >>
6565 for (unsigned i = 0; i != NumArgs; ++i) {
6666 MVT::ValueType ArgVT = TheArgs->getValueType(i);
6767 SDOperand FlagOp = TheArgs->getOperand(3+i);
68 unsigned ArgFlags = cast(FlagOp)->getValue();
68 ISD::ParamFlags::ParamFlagsTy ArgFlags =
69 cast(FlagOp)->getValue();
6970 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
7071 cerr << "Formal argument #" << i << " has unhandled type "
7172 << MVT::getValueTypeString(ArgVT) << "\n";
9798 for (unsigned i = 0; i != NumOps; ++i) {
9899 MVT::ValueType ArgVT = TheCall->getOperand(5+2*i).getValueType();
99100 SDOperand FlagOp = TheCall->getOperand(5+2*i+1);
100 unsigned ArgFlags =cast(FlagOp)->getValue();
101 ISD::ParamFlags::ParamFlagsTy ArgFlags =
102 cast(FlagOp)->getValue();
101103 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
102104 cerr << "Call operand #" << i << " has unhandled type "
103105 << MVT::getValueTypeString(ArgVT) << "\n";
40584058 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end();
40594059 I != E; ++I, ++j) {
40604060 MVT::ValueType VT = getValueType(I->getType());
4061 unsigned Flags = ISD::ParamFlags::NoFlagSet;
4061 ISD::ParamFlags::ParamFlagsTy Flags = ISD::ParamFlags::NoFlagSet;
40624062 unsigned OriginalAlignment =
40634063 getTargetData()->getABITypeAlignment(I->getType());
40644064
40824082 // this info is not there but there are cases it cannot get right.
40834083 if (F.getParamAlignment(j))
40844084 FrameAlign = Log2_32(F.getParamAlignment(j));
4085 Flags |= (FrameAlign << ISD::ParamFlags::ByValAlignOffs);
4086 Flags |= (FrameSize << ISD::ParamFlags::ByValSizeOffs);
4085 Flags |= ((ISD::ParamFlags::ParamFlagsTy)FrameAlign
4086 << ISD::ParamFlags::ByValAlignOffs);
4087 Flags |= ((ISD::ParamFlags::ParamFlagsTy)FrameSize
4088 << ISD::ParamFlags::ByValSizeOffs);
40874089 }
40884090 if (F.paramHasAttr(j, ParamAttr::Nest))
40894091 Flags |= ISD::ParamFlags::Nest;
4090 Flags |= (OriginalAlignment << ISD::ParamFlags::OrigAlignmentOffs);
4092 Flags |= ((ISD::ParamFlags::ParamFlagsTy)OriginalAlignment
4093 << ISD::ParamFlags::OrigAlignmentOffs);
40914094
40924095 MVT::ValueType RegisterVT = getRegisterType(VT);
40934096 unsigned NumRegs = getNumRegisters(VT);
40964099 // if it isn't first piece, alignment must be 1
40974100 if (i > 0)
40984101 Flags = (Flags & (~ISD::ParamFlags::OrigAlignment)) |
4099 (1 << ISD::ParamFlags::OrigAlignmentOffs);
4100 Ops.push_back(DAG.getConstant(Flags, MVT::i32));
4102 (ISD::ParamFlags::One << ISD::ParamFlags::OrigAlignmentOffs);
4103 Ops.push_back(DAG.getConstant(Flags, MVT::i64));
41014104 }
41024105 }
41034106
41734176 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
41744177 MVT::ValueType VT = getValueType(Args[i].Ty);
41754178 SDOperand Op = Args[i].Node;
4176 unsigned Flags = ISD::ParamFlags::NoFlagSet;
4179 ISD::ParamFlags::ParamFlagsTy Flags = ISD::ParamFlags::NoFlagSet;
41774180 unsigned OriginalAlignment =
41784181 getTargetData()->getABITypeAlignment(Args[i].Ty);
41794182
41954198 // info is not there but there are cases it cannot get right.
41964199 if (Args[i].Alignment)
41974200 FrameAlign = Log2_32(Args[i].Alignment);
4198 Flags |= (FrameAlign << ISD::ParamFlags::ByValAlignOffs);
4199 Flags |= (FrameSize << ISD::ParamFlags::ByValSizeOffs);
4201 Flags |= ((ISD::ParamFlags::ParamFlagsTy)FrameAlign
4202 << ISD::ParamFlags::ByValAlignOffs);
4203 Flags |= ((ISD::ParamFlags::ParamFlagsTy)FrameSize
4204 << ISD::ParamFlags::ByValSizeOffs);
42004205 }
42014206 if (Args[i].isNest)
42024207 Flags |= ISD::ParamFlags::Nest;
4203 Flags |= OriginalAlignment << ISD::ParamFlags::OrigAlignmentOffs;
4208 Flags |= ((ISD::ParamFlags::ParamFlagsTy)OriginalAlignment)
4209 << ISD::ParamFlags::OrigAlignmentOffs;
42044210
42054211 MVT::ValueType PartVT = getRegisterType(VT);
42064212 unsigned NumParts = getNumRegisters(VT);
42164222
42174223 for (unsigned i = 0; i != NumParts; ++i) {
42184224 // if it isn't first piece, alignment must be 1
4219 unsigned MyFlags = Flags;
4225 ISD::ParamFlags::ParamFlagsTy MyFlags = Flags;
42204226 if (i != 0)
42214227 MyFlags = (MyFlags & (~ISD::ParamFlags::OrigAlignment)) |
4222 (1 << ISD::ParamFlags::OrigAlignmentOffs);
4228 (ISD::ParamFlags::One << ISD::ParamFlags::OrigAlignmentOffs);
42234229
42244230 Ops.push_back(Parts[i]);
4225 Ops.push_back(DAG.getConstant(MyFlags, MVT::i32));
4231 Ops.push_back(DAG.getConstant(MyFlags, MVT::i64));
42264232 }
42274233 }
42284234
367367 HowToPassArgument(MVT::ValueType ObjectVT, unsigned NumGPRs,
368368 unsigned StackOffset, unsigned &NeededGPRs,
369369 unsigned &NeededStackSize, unsigned &GPRPad,
370 unsigned &StackPad, unsigned Flags) {
370 unsigned &StackPad, ISD::ParamFlags::ParamFlagsTy Flags) {
371371 NeededStackSize = 0;
372372 NeededGPRs = 0;
373373 StackPad = 0;
374374 GPRPad = 0;
375 unsigned align = (Flags >> ISD::ParamFlags::OrigAlignmentOffs);
375 unsigned align = ((Flags & ISD::ParamFlags::OrigAlignment)
376 >> ISD::ParamFlags::OrigAlignmentOffs);
376377 GPRPad = NumGPRs % ((align + 3)/4);
377378 StackPad = StackOffset % align;
378379 unsigned firstGPR = NumGPRs + GPRPad;
421422 unsigned StackPad;
422423 unsigned GPRPad;
423424 MVT::ValueType ObjectVT = Op.getOperand(5+2*i).getValueType();
424 unsigned Flags = Op.getConstantOperandVal(5+2*i+1);
425 ISD::ParamFlags::ParamFlagsTy Flags = Op.getConstantOperandVal(5+2*i+1);
425426 HowToPassArgument(ObjectVT, NumGPRs, NumBytes, ObjGPRs, ObjSize,
426427 GPRPad, StackPad, Flags);
427428 NumBytes += ObjSize + StackPad;
444445 std::vector MemOpChains;
445446 for (unsigned i = 0; i != NumOps; ++i) {
446447 SDOperand Arg = Op.getOperand(5+2*i);
447 unsigned Flags = Op.getConstantOperandVal(5+2*i+1);
448 ISD::ParamFlags::ParamFlagsTy Flags = Op.getConstantOperandVal(5+2*i+1);
448449 MVT::ValueType ArgVT = Arg.getValueType();
449450
450451 unsigned ObjSize;
923924 unsigned ObjGPRs;
924925 unsigned GPRPad;
925926 unsigned StackPad;
926 unsigned Flags = Op.getConstantOperandVal(ArgNo + 3);
927 ISD::ParamFlags::ParamFlagsTy Flags = Op.getConstantOperandVal(ArgNo + 3);
927928 HowToPassArgument(ObjectVT, NumGPRs, ArgOffset, ObjGPRs,
928929 ObjSize, GPRPad, StackPad, Flags);
929930 NumGPRs += GPRPad;
13601360 MVT::ValueType ObjectVT = Op.getValue(ArgNo).getValueType();
13611361 unsigned ObjSize = MVT::getSizeInBits(ObjectVT)/8;
13621362 unsigned ArgSize = ObjSize;
1363 unsigned Flags = cast(Op.getOperand(ArgNo+3))->getValue();
1364 unsigned AlignFlag = 1 << ISD::ParamFlags::OrigAlignmentOffs;
1363 ISD::ParamFlags::ParamFlagsTy Flags =
1364 cast(Op.getOperand(ArgNo+3))->getValue();
1365 unsigned AlignFlag = ISD::ParamFlags::One
1366 << ISD::ParamFlags::OrigAlignmentOffs;
13651367 unsigned isByVal = Flags & ISD::ParamFlags::ByVal;
13661368 // See if next argument requires stack alignment in ELF
13671369 bool Expand = (ObjectVT == MVT::f64) || ((ArgNo + 1 < e) &&
16581660 /// does not fit in registers.
16591661 static SDOperand
16601662 CreateCopyOfByValArgument(SDOperand Src, SDOperand Dst, SDOperand Chain,
1661 unsigned Flags, SelectionDAG &DAG, unsigned Size) {
1662 unsigned Align = 1 <<
1663 ISD::ParamFlags::ParamFlagsTy Flags,
1664 SelectionDAG &DAG, unsigned Size) {
1665 unsigned Align = ISD::ParamFlags::One <<
16631666 ((Flags & ISD::ParamFlags::ByValAlign) >> ISD::ParamFlags::ByValAlignOffs);
16641667 SDOperand AlignNode = DAG.getConstant(Align, MVT::i32);
16651668 SDOperand SizeNode = DAG.getConstant(Size, MVT::i32);
16921695
16931696 // Add up all the space actually used.
16941697 for (unsigned i = 0; i != NumOps; ++i) {
1695 unsigned Flags = cast(Op.getOperand(5+2*i+1))->getValue();
1698 ISD::ParamFlags::ParamFlagsTy Flags =
1699 cast(Op.getOperand(5+2*i+1))->getValue();
16961700 unsigned ArgSize =MVT::getSizeInBits(Op.getOperand(5+2*i).getValueType())/8;
16971701 if (Flags & ISD::ParamFlags::ByVal)
16981702 ArgSize = (Flags & ISD::ParamFlags::ByValSize) >>
17561760 for (unsigned i = 0; i != NumOps; ++i) {
17571761 bool inMem = false;
17581762 SDOperand Arg = Op.getOperand(5+2*i);
1759 unsigned Flags = cast(Op.getOperand(5+2*i+1))->getValue();
1760 unsigned AlignFlag = 1 << ISD::ParamFlags::OrigAlignmentOffs;
1763 ISD::ParamFlags::ParamFlagsTy Flags =
1764 cast(Op.getOperand(5+2*i+1))->getValue();
1765 unsigned AlignFlag = ISD::ParamFlags::One <<
1766 ISD::ParamFlags::OrigAlignmentOffs;
17611767 // See if next argument requires stack alignment in ELF
17621768 unsigned next = 5+2*(i+1)+1;
17631769 bool Expand = (Arg.getValueType() == MVT::f64) || ((i + 1 < NumOps) &&
11441144 /// parameter.
11451145 static SDOperand
11461146 CreateCopyOfByValArgument(SDOperand Src, SDOperand Dst, SDOperand Chain,
1147 unsigned Flags, SelectionDAG &DAG) {
1148 unsigned Align = 1 <<
1147 ISD::ParamFlags::ParamFlagsTy Flags,
1148 SelectionDAG &DAG) {
1149 unsigned Align = ISD::ParamFlags::One <<
11491150 ((Flags & ISD::ParamFlags::ByValAlign) >> ISD::ParamFlags::ByValAlignOffs);
11501151 unsigned Size = (Flags & ISD::ParamFlags::ByValSize) >>
11511152 ISD::ParamFlags::ByValSizeOffs;
11611162 unsigned CC,
11621163 SDOperand Root, unsigned i) {
11631164 // Create the nodes corresponding to a load from this parameter slot.
1164 unsigned Flags = cast(Op.getOperand(3 + i))->getValue();
1165 ISD::ParamFlags::ParamFlagsTy Flags =
1166 cast(Op.getOperand(3 + i))->getValue();
11651167 bool AlwaysUseMutable = (CC==CallingConv::Fast) && PerformTailCallOpt;
11661168 bool isByVal = Flags & ISD::ParamFlags::ByVal;
11671169 bool isImmutable = !AlwaysUseMutable && !isByVal;
13791381 SDOperand PtrOff = DAG.getIntPtrConstant(LocMemOffset);
13801382 PtrOff = DAG.getNode(ISD::ADD, getPointerTy(), StackPtr, PtrOff);
13811383 SDOperand FlagsOp = Op.getOperand(6+2*VA.getValNo());
1382 unsigned Flags = cast(FlagsOp)->getValue();
1384 ISD::ParamFlags::ParamFlagsTy Flags =
1385 cast(FlagsOp)->getValue();
13831386 if (Flags & ISD::ParamFlags::ByVal) {
13841387 return CreateCopyOfByValArgument(Arg, PtrOff, Chain, Flags, DAG);
13851388 }
16411644 assert(VA.isMemLoc());
16421645 SDOperand Arg = Op.getOperand(5+2*VA.getValNo());
16431646 SDOperand FlagsOp = Op.getOperand(6+2*VA.getValNo());
1644 unsigned Flags = cast(FlagsOp)->getValue();
1647 ISD::ParamFlags::ParamFlagsTy Flags =
1648 cast(FlagsOp)->getValue();
16451649 // Create frame index.
16461650 int32_t Offset = VA.getLocMemOffset()+FPDiff;
16471651 uint32_t OpSize = (MVT::getSizeInBits(VA.getLocVT())+7)/8;
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 << "unsigned ArgFlags, CCState &State);\n";
32 << "ISD::ParamFlags::ParamFlagsTy 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 << "unsigned ArgFlags, CCState &State) {\n";
50 << "ISD::ParamFlags::ParamFlagsTy 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";