diff options
author | Evan Cheng <evan.cheng@apple.com> | 2009-10-18 18:16:27 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2009-10-18 18:16:27 +0000 |
commit | ff89dcb06fbd103373436e2d0ae85f252fae2254 (patch) | |
tree | a9c2c0c4ab7512a79f6bd15d41caa381e2cccf7c /lib/CodeGen | |
parent | 20270c909357e5e501cac1f5393430dfacfc57d8 (diff) | |
download | external_llvm-ff89dcb06fbd103373436e2d0ae85f252fae2254.zip external_llvm-ff89dcb06fbd103373436e2d0ae85f252fae2254.tar.gz external_llvm-ff89dcb06fbd103373436e2d0ae85f252fae2254.tar.bz2 |
-Revert parts of 84326 and 84411. Distinquishing between fixed and non-fixed
stack slots and giving them different PseudoSourceValue's did not fix the
problem of post-alloc scheduling miscompiling llvm itself.
- Apply Dan's conservative workaround by assuming any non fixed stack slots can
alias other memory locations. This means a load from spill slot #1 cannot
move above a store of spill slot #2.
- Enable post-alloc scheduling for x86 at optimization leverl Default and above.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84424 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/PseudoSourceValue.cpp | 19 | ||||
-rw-r--r-- | lib/CodeGen/ScheduleDAGInstrs.cpp | 15 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 27 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp | 3 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp | 3 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 56 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/StackSlotColoring.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/TargetInstrInfoImpl.cpp | 5 |
9 files changed, 73 insertions, 67 deletions
diff --git a/lib/CodeGen/PseudoSourceValue.cpp b/lib/CodeGen/PseudoSourceValue.cpp index 00c5d46..289a52b 100644 --- a/lib/CodeGen/PseudoSourceValue.cpp +++ b/lib/CodeGen/PseudoSourceValue.cpp @@ -63,6 +63,8 @@ namespace { virtual bool isConstant(const MachineFrameInfo *MFI) const; + virtual bool isAliased() const; + virtual void printCustom(raw_ostream &OS) const { OS << "FixedStack" << FI; } @@ -89,6 +91,23 @@ bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { return false; } +bool PseudoSourceValue::isAliased() const { + if (this == getStack() || + this == getGOT() || + this == getConstantPool() || + this == getJumpTable()) + return false; + llvm_unreachable("Unknown PseudoSourceValue!"); + return true; +} + bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{ return MFI && MFI->isImmutableObjectIndex(FI); } + +bool FixedStackPseudoSourceValue::isAliased() const{ + // Negative frame indices are used for special things that don't + // appear in LLVM IR. Non-negative indices may be used for things + // like static allocas. + return FI >= 0; +} diff --git a/lib/CodeGen/ScheduleDAGInstrs.cpp b/lib/CodeGen/ScheduleDAGInstrs.cpp index 44e9296..768ca16 100644 --- a/lib/CodeGen/ScheduleDAGInstrs.cpp +++ b/lib/CodeGen/ScheduleDAGInstrs.cpp @@ -106,10 +106,19 @@ static const Value *getUnderlyingObjectForInstr(const MachineInstr *MI) { return 0; V = getUnderlyingObject(V); - if (!isa<PseudoSourceValue>(V) && !isIdentifiedObject(V)) - return 0; + if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) { + // For now, ignore PseudoSourceValues which may alias LLVM IR values + // because the code that uses this function has no way to cope with + // such aliases. + if (PSV->isAliased()) + return 0; + return V; + } - return V; + if (isIdentifiedObject(V)) + return V; + + return 0; } void ScheduleDAGInstrs::StartBlock(MachineBasicBlock *BB) { diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 0adffbb..7138dd2 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -639,9 +639,11 @@ PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, SDValue Idx, EVT PtrVT = TLI.getPointerTy(); SDValue StackPtr = DAG.CreateStackTemporary(VT); + int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex(); + // Store the vector. SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Tmp1, StackPtr, - PseudoSourceValue::getStack(), 0); + PseudoSourceValue::getFixedStack(SPFI), 0); // Truncate or zero extend offset to target pointer type. unsigned CastOpc = IdxVT.bitsGT(PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; @@ -652,10 +654,10 @@ PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, SDValue Idx, SDValue StackPtr2 = DAG.getNode(ISD::ADD, dl, IdxVT, Tmp3, StackPtr); // Store the scalar value. Ch = DAG.getTruncStore(Ch, dl, Tmp2, StackPtr2, - PseudoSourceValue::getStack(), 0, EltVT); + PseudoSourceValue::getFixedStack(SPFI), 0, EltVT); // Load the updated vector. return DAG.getLoad(VT, dl, Ch, StackPtr, - PseudoSourceValue::getStack(), 0); + PseudoSourceValue::getFixedStack(SPFI), 0); } @@ -1515,7 +1517,8 @@ SDValue SelectionDAGLegalize::ExpandVectorBuildThroughStack(SDNode* Node) { EVT OpVT = Node->getOperand(0).getValueType(); DebugLoc dl = Node->getDebugLoc(); SDValue FIPtr = DAG.CreateStackTemporary(VT); - const Value *SV = PseudoSourceValue::getStack(); + int FI = cast<FrameIndexSDNode>(FIPtr.getNode())->getIndex(); + const Value *SV = PseudoSourceValue::getFixedStack(FI); // Emit a store of each element to the stack slot. SmallVector<SDValue, 8> Stores; @@ -1709,17 +1712,20 @@ SDValue SelectionDAGLegalize::EmitStackConvert(SDValue SrcOp, getTypeForEVT(*DAG.getContext())); SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign); + FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr); + int SPFI = StackPtrFI->getIndex(); + const Value *SV = PseudoSourceValue::getFixedStack(SPFI); + unsigned SrcSize = SrcOp.getValueType().getSizeInBits(); unsigned SlotSize = SlotVT.getSizeInBits(); unsigned DestSize = DestVT.getSizeInBits(); unsigned DestAlign = - TLI.getTargetData()->getPrefTypeAlignment(DestVT. - getTypeForEVT(*DAG.getContext())); + TLI.getTargetData()->getPrefTypeAlignment(DestVT.getTypeForEVT(*DAG.getContext())); // Emit a store to the stack slot. Use a truncstore if the input value is // later than DestVT. SDValue Store; - const Value *SV = PseudoSourceValue::getStack(); + if (SrcSize > SlotSize) Store = DAG.getTruncStore(DAG.getEntryNode(), dl, SrcOp, FIPtr, SV, 0, SlotVT, false, SrcAlign); @@ -1744,12 +1750,15 @@ SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { // then load the whole vector back out. SDValue StackPtr = DAG.CreateStackTemporary(Node->getValueType(0)); + FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr); + int SPFI = StackPtrFI->getIndex(); + SDValue Ch = DAG.getTruncStore(DAG.getEntryNode(), dl, Node->getOperand(0), StackPtr, - PseudoSourceValue::getStack(), 0, + PseudoSourceValue::getFixedStack(SPFI), 0, Node->getValueType(0).getVectorElementType()); return DAG.getLoad(Node->getValueType(0), dl, Ch, StackPtr, - PseudoSourceValue::getStack(), 0); + PseudoSourceValue::getFixedStack(SPFI), 0); } diff --git a/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp b/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp index 29f1a2d..dbd3e39 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp @@ -118,7 +118,8 @@ void DAGTypeLegalizer::ExpandRes_BIT_CONVERT(SDNode *N, SDValue &Lo, TLI.getTargetData()->getPrefTypeAlignment(NOutVT. getTypeForEVT(*DAG.getContext())); SDValue StackPtr = DAG.CreateStackTemporary(InVT, Alignment); - const Value *SV = PseudoSourceValue::getStack(); + int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex(); + const Value *SV = PseudoSourceValue::getFixedStack(SPFI); // Emit a store to the stack slot. SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, InOp, StackPtr, SV, 0); diff --git a/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp index 1964f64..75e1239 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -1057,7 +1057,8 @@ SDValue DAGTypeLegalizer::SplitVecOp_EXTRACT_VECTOR_ELT(SDNode *N) { EVT EltVT = VecVT.getVectorElementType(); DebugLoc dl = N->getDebugLoc(); SDValue StackPtr = DAG.CreateStackTemporary(VecVT); - const Value *SV = PseudoSourceValue::getStack(); + int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex(); + const Value *SV = PseudoSourceValue::getFixedStack(SPFI); SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, SV, 0); // Load back the required element. diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index cd7e1fd..8bd0370 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -3507,22 +3507,16 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT, SDValue Ptr, SDValue Cmp, SDValue Swp, const Value* PtrVal, unsigned Alignment) { - MachineFunction &MF = getMachineFunction(); - MachineFrameInfo *FrameInfo = MF.getFrameInfo(); - if (Alignment == 0) // Ensure that codegen never sees alignment 0 Alignment = getEVTAlignment(MemVT); // Check if the memory reference references a frame index if (!PtrVal) if (const FrameIndexSDNode *FI = - dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) { - if (FrameInfo->isFixedObjectIndex(FI->getIndex())) - PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex()); - else - PtrVal = PseudoSourceValue::getStack(); - } + dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) + PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex()); + MachineFunction &MF = getMachineFunction(); unsigned Flags = MachineMemOperand::MOLoad | MachineMemOperand::MOStore; // For now, atomics are considered to be volatile always. @@ -3566,21 +3560,16 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT, SDValue Ptr, SDValue Val, const Value* PtrVal, unsigned Alignment) { - MachineFunction &MF = getMachineFunction(); - MachineFrameInfo *FrameInfo = MF.getFrameInfo(); - if (Alignment == 0) // Ensure that codegen never sees alignment 0 Alignment = getEVTAlignment(MemVT); // Check if the memory reference references a frame index if (!PtrVal) if (const FrameIndexSDNode *FI = - dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) - if (FrameInfo->isFixedObjectIndex(FI->getIndex())) - PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex()); - else - PtrVal = PseudoSourceValue::getStack(); + dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) + PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex()); + MachineFunction &MF = getMachineFunction(); unsigned Flags = MachineMemOperand::MOLoad | MachineMemOperand::MOStore; // For now, atomics are considered to be volatile always. @@ -3718,21 +3707,16 @@ SelectionDAG::getLoad(ISD::MemIndexedMode AM, DebugLoc dl, SDValue Ptr, SDValue Offset, const Value *SV, int SVOffset, EVT MemVT, bool isVolatile, unsigned Alignment) { - MachineFunction &MF = getMachineFunction(); - MachineFrameInfo *FrameInfo = MF.getFrameInfo(); - if (Alignment == 0) // Ensure that codegen never sees alignment 0 Alignment = getEVTAlignment(VT); // Check if the memory reference references a frame index if (!SV) if (const FrameIndexSDNode *FI = - dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) - if (FrameInfo->isFixedObjectIndex(FI->getIndex())) - SV = PseudoSourceValue::getFixedStack(FI->getIndex()); - else - SV = PseudoSourceValue::getStack(); + dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) + SV = PseudoSourceValue::getFixedStack(FI->getIndex()); + MachineFunction &MF = getMachineFunction(); unsigned Flags = MachineMemOperand::MOLoad; if (isVolatile) Flags |= MachineMemOperand::MOVolatile; @@ -3822,21 +3806,16 @@ SelectionDAG::getIndexedLoad(SDValue OrigLoad, DebugLoc dl, SDValue Base, SDValue SelectionDAG::getStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr, const Value *SV, int SVOffset, bool isVolatile, unsigned Alignment) { - MachineFunction &MF = getMachineFunction(); - MachineFrameInfo *FrameInfo = MF.getFrameInfo(); - if (Alignment == 0) // Ensure that codegen never sees alignment 0 Alignment = getEVTAlignment(Val.getValueType()); // Check if the memory reference references a frame index if (!SV) if (const FrameIndexSDNode *FI = - dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) - if (FrameInfo->isFixedObjectIndex(FI->getIndex())) - SV = PseudoSourceValue::getFixedStack(FI->getIndex()); - else - SV = PseudoSourceValue::getStack(); + dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) + SV = PseudoSourceValue::getFixedStack(FI->getIndex()); + MachineFunction &MF = getMachineFunction(); unsigned Flags = MachineMemOperand::MOStore; if (isVolatile) Flags |= MachineMemOperand::MOVolatile; @@ -3873,21 +3852,16 @@ SDValue SelectionDAG::getTruncStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr, const Value *SV, int SVOffset, EVT SVT, bool isVolatile, unsigned Alignment) { - MachineFunction &MF = getMachineFunction(); - MachineFrameInfo *FrameInfo = MF.getFrameInfo(); - if (Alignment == 0) // Ensure that codegen never sees alignment 0 Alignment = getEVTAlignment(SVT); // Check if the memory reference references a frame index if (!SV) if (const FrameIndexSDNode *FI = - dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) - if (FrameInfo->isFixedObjectIndex(FI->getIndex())) - SV = PseudoSourceValue::getFixedStack(FI->getIndex()); - else - SV = PseudoSourceValue::getStack(); + dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) + SV = PseudoSourceValue::getFixedStack(FI->getIndex()); + MachineFunction &MF = getMachineFunction(); unsigned Flags = MachineMemOperand::MOStore; if (isVolatile) Flags |= MachineMemOperand::MOVolatile; diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 9c22202..adcc532 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -4196,11 +4196,9 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { SDValue FIN = DAG.getFrameIndex(FI, PtrTy); // Store the stack protector onto the stack. - const Value *SV = MFI->isFixedObjectIndex(FI) - ? PseudoSourceValue::getFixedStack(FI) - : PseudoSourceValue::getStack(); SDValue Result = DAG.getStore(getRoot(), getCurDebugLoc(), Src, FIN, - SV, 0, true); + PseudoSourceValue::getFixedStack(FI), + 0, true); setValue(&I, Result); DAG.setRoot(Result); return 0; diff --git a/lib/CodeGen/StackSlotColoring.cpp b/lib/CodeGen/StackSlotColoring.cpp index 62b2c49..fad0808 100644 --- a/lib/CodeGen/StackSlotColoring.cpp +++ b/lib/CodeGen/StackSlotColoring.cpp @@ -466,10 +466,8 @@ void StackSlotColoring::RewriteInstruction(MachineInstr *MI, int OldFI, // Update the memory references. This changes the MachineMemOperands // directly. They may be in use by multiple instructions, however all // instructions using OldFI are being rewritten to use NewFI. - const Value *OldSV = MFI->isFixedObjectIndex(OldFI) - ? PseudoSourceValue::getFixedStack(OldFI) : PseudoSourceValue::getStack(); - const Value *NewSV = MFI->isFixedObjectIndex(NewFI) - ? PseudoSourceValue::getFixedStack(NewFI) : PseudoSourceValue::getStack(); + const Value *OldSV = PseudoSourceValue::getFixedStack(OldFI); + const Value *NewSV = PseudoSourceValue::getFixedStack(NewFI); for (MachineInstr::mmo_iterator I = MI->memoperands_begin(), E = MI->memoperands_end(); I != E; ++I) if ((*I)->getValue() == OldSV) diff --git a/lib/CodeGen/TargetInstrInfoImpl.cpp b/lib/CodeGen/TargetInstrInfoImpl.cpp index 0a925f1..c646869 100644 --- a/lib/CodeGen/TargetInstrInfoImpl.cpp +++ b/lib/CodeGen/TargetInstrInfoImpl.cpp @@ -186,11 +186,8 @@ TargetInstrInfo::foldMemoryOperand(MachineFunction &MF, "Folded a use to a non-load!"); const MachineFrameInfo &MFI = *MF.getFrameInfo(); assert(MFI.getObjectOffset(FrameIndex) != -1); - const Value *SV = MFI.isFixedObjectIndex(FrameIndex) - ? PseudoSourceValue::getFixedStack(FrameIndex) - : PseudoSourceValue::getStack(); MachineMemOperand *MMO = - MF.getMachineMemOperand(SV, + MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FrameIndex), Flags, /*Offset=*/0, MFI.getObjectSize(FrameIndex), MFI.getObjectAlignment(FrameIndex)); |