From owner-svn-src-stable-9@FreeBSD.ORG Sun Jul 7 19:05:37 2013 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 5F84ACE6; Sun, 7 Jul 2013 19:05:37 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 4FB1D10C9; Sun, 7 Jul 2013 19:05:37 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r67J5bTm001669; Sun, 7 Jul 2013 19:05:37 GMT (envelope-from dim@svn.freebsd.org) Received: (from dim@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r67J5aqL001660; Sun, 7 Jul 2013 19:05:36 GMT (envelope-from dim@svn.freebsd.org) Message-Id: <201307071905.r67J5aqL001660@svn.freebsd.org> From: Dimitry Andric Date: Sun, 7 Jul 2013 19:05:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r252993 - in stable/9/contrib/llvm: include/llvm/CodeGen lib/CodeGen lib/CodeGen/SelectionDAG X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jul 2013 19:05:37 -0000 Author: dim Date: Sun Jul 7 19:05:35 2013 New Revision: 252993 URL: http://svnweb.freebsd.org/changeset/base/252993 Log: MFC r252720: Pull in r185594 from llvm trunk: Add MachineBasicBlock::addLiveIn(). This function adds a live-in physical register to an MBB and ensures that it is copied to a virtual register immediately. Pull in r185615 from llvm trunk: Live-in copies go *after* EH_LABELs. This will soon be tested by exception handling working at all. Pull in r185617 from llvm trunk: Simplify landing pad lowering. Stop using the ISD::EXCEPTIONADDR and ISD::EHSELECTION when lowering landing pad arguments. These nodes were previously legalized into CopyFromReg nodes, but that never worked properly because the CopyFromReg node weren't guaranteed to be scheduled at the top of the basic block. This meant the exception pointer and selector registers could be clobbered before being copied to a virtual register. This patch copies the two physical registers to virtual registers at the beginning of the basic block, and lowers the landingpad instruction directly to two CopyFromReg nodes reading the *virtual* registers. This is safe because virtual registers don't get clobbered. A future patch will remove the ISD::EXCEPTIONADDR and ISD::EHSELECTION nodes. Together, these changes fix llvm PR 16038 ('qt4 webcore file results in "Bad machine code: Using an undefined physical register"'), and should make it possible again to compile the www/qt4-webkit port again on the i386 arch, without using a CPUTYPE=i686 or higher setting. Modified: stable/9/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h stable/9/contrib/llvm/include/llvm/CodeGen/MachineBasicBlock.h stable/9/contrib/llvm/lib/CodeGen/MachineBasicBlock.cpp stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Directory Properties: stable/9/contrib/llvm/ (props changed) Modified: stable/9/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h ============================================================================== --- stable/9/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h Sun Jul 7 19:04:10 2013 (r252992) +++ stable/9/contrib/llvm/include/llvm/CodeGen/FunctionLoweringInfo.h Sun Jul 7 19:05:35 2013 (r252993) @@ -115,6 +115,11 @@ public: /// there's no other convenient place for it to live right now. std::vector > PHINodesToUpdate; + /// If the current MBB is a landing pad, the exception pointer and exception + /// selector registers are copied into these virtual registers by + /// SelectionDAGISel::PrepareEHLandingPad(). + unsigned ExceptionPointerVirtReg, ExceptionSelectorVirtReg; + explicit FunctionLoweringInfo(const TargetLowering &TLI); /// set - Initialize this FunctionLoweringInfo with the given Function Modified: stable/9/contrib/llvm/include/llvm/CodeGen/MachineBasicBlock.h ============================================================================== --- stable/9/contrib/llvm/include/llvm/CodeGen/MachineBasicBlock.h Sun Jul 7 19:04:10 2013 (r252992) +++ stable/9/contrib/llvm/include/llvm/CodeGen/MachineBasicBlock.h Sun Jul 7 19:05:35 2013 (r252993) @@ -296,6 +296,11 @@ public: /// is an error to add the same register to the same set more than once. void addLiveIn(unsigned Reg) { LiveIns.push_back(Reg); } + /// Add PhysReg as live in to this block, and ensure that there is a copy of + /// PhysReg to a virtual register of class RC. Return the virtual register + /// that is a copy of the live in PhysReg. + unsigned addLiveIn(unsigned PhysReg, const TargetRegisterClass *RC); + /// removeLiveIn - Remove the specified register from the live in set. /// void removeLiveIn(unsigned Reg); Modified: stable/9/contrib/llvm/lib/CodeGen/MachineBasicBlock.cpp ============================================================================== --- stable/9/contrib/llvm/lib/CodeGen/MachineBasicBlock.cpp Sun Jul 7 19:04:10 2013 (r252992) +++ stable/9/contrib/llvm/lib/CodeGen/MachineBasicBlock.cpp Sun Jul 7 19:05:35 2013 (r252993) @@ -19,6 +19,7 @@ #include "llvm/CodeGen/LiveVariables.h" #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineLoopInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/SlotIndexes.h" @@ -341,6 +342,38 @@ bool MachineBasicBlock::isLiveIn(unsigne return I != livein_end(); } +unsigned +MachineBasicBlock::addLiveIn(unsigned PhysReg, const TargetRegisterClass *RC) { + assert(getParent() && "MBB must be inserted in function"); + assert(TargetRegisterInfo::isPhysicalRegister(PhysReg) && "Expected physreg"); + assert(RC && "Register class is required"); + assert((isLandingPad() || this == &getParent()->front()) && + "Only the entry block and landing pads can have physreg live ins"); + + bool LiveIn = isLiveIn(PhysReg); + iterator I = SkipPHIsAndLabels(begin()), E = end(); + MachineRegisterInfo &MRI = getParent()->getRegInfo(); + const TargetInstrInfo &TII = *getParent()->getTarget().getInstrInfo(); + + // Look for an existing copy. + if (LiveIn) + for (;I != E && I->isCopy(); ++I) + if (I->getOperand(1).getReg() == PhysReg) { + unsigned VirtReg = I->getOperand(0).getReg(); + if (!MRI.constrainRegClass(VirtReg, RC)) + llvm_unreachable("Incompatible live-in register class."); + return VirtReg; + } + + // No luck, create a virtual register. + unsigned VirtReg = MRI.createVirtualRegister(RC); + BuildMI(*this, I, DebugLoc(), TII.get(TargetOpcode::COPY), VirtReg) + .addReg(PhysReg, RegState::Kill); + if (!LiveIn) + addLiveIn(PhysReg); + return VirtReg; +} + void MachineBasicBlock::moveBefore(MachineBasicBlock *NewAfter) { getParent()->splice(NewAfter, this); } Modified: stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp ============================================================================== --- stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Sun Jul 7 19:04:10 2013 (r252992) +++ stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Sun Jul 7 19:05:35 2013 (r252993) @@ -1910,33 +1910,25 @@ void SelectionDAGBuilder::visitLandingPa SmallVector ValueVTs; ComputeValueVTs(TLI, LP.getType(), ValueVTs); + assert(ValueVTs.size() == 2 && "Only two-valued landingpads are supported"); - // Insert the EXCEPTIONADDR instruction. - assert(FuncInfo.MBB->isLandingPad() && - "Call to eh.exception not in landing pad!"); - SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other); + // Get the two live-in registers as SDValues. The physregs have already been + // copied into virtual registers. SDValue Ops[2]; - Ops[0] = DAG.getRoot(); - SDValue Op1 = DAG.getNode(ISD::EXCEPTIONADDR, getCurDebugLoc(), VTs, Ops, 1); - SDValue Chain = Op1.getValue(1); - - // Insert the EHSELECTION instruction. - VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other); - Ops[0] = Op1; - Ops[1] = Chain; - SDValue Op2 = DAG.getNode(ISD::EHSELECTION, getCurDebugLoc(), VTs, Ops, 2); - Chain = Op2.getValue(1); - Op2 = DAG.getSExtOrTrunc(Op2, getCurDebugLoc(), MVT::i32); + Ops[0] = DAG.getZExtOrTrunc( + DAG.getCopyFromReg(DAG.getEntryNode(), getCurDebugLoc(), + FuncInfo.ExceptionPointerVirtReg, TLI.getPointerTy()), + getCurDebugLoc(), ValueVTs[0]); + Ops[1] = DAG.getZExtOrTrunc( + DAG.getCopyFromReg(DAG.getEntryNode(), getCurDebugLoc(), + FuncInfo.ExceptionSelectorVirtReg, TLI.getPointerTy()), + getCurDebugLoc(), ValueVTs[1]); - Ops[0] = Op1; - Ops[1] = Op2; + // Merge into one. SDValue Res = DAG.getNode(ISD::MERGE_VALUES, getCurDebugLoc(), DAG.getVTList(&ValueVTs[0], ValueVTs.size()), &Ops[0], 2); - - std::pair RetPair = std::make_pair(Res, Chain); - setValue(&LP, RetPair.first); - DAG.setRoot(RetPair.second); + setValue(&LP, Res); } /// handleSmallSwitchCaseRange - Emit a series of specific tests (suitable for Modified: stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp ============================================================================== --- stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Sun Jul 7 19:04:10 2013 (r252992) +++ stable/9/contrib/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Sun Jul 7 19:05:35 2013 (r252993) @@ -827,12 +827,13 @@ void SelectionDAGISel::PrepareEHLandingP .addSym(Label); // Mark exception register as live in. - unsigned Reg = TLI.getExceptionPointerRegister(); - if (Reg) MBB->addLiveIn(Reg); + const TargetRegisterClass *PtrRC = TLI.getRegClassFor(TLI.getPointerTy()); + if (unsigned Reg = TLI.getExceptionPointerRegister()) + FuncInfo->ExceptionPointerVirtReg = MBB->addLiveIn(Reg, PtrRC); // Mark exception selector register as live in. - Reg = TLI.getExceptionSelectorRegister(); - if (Reg) MBB->addLiveIn(Reg); + if (unsigned Reg = TLI.getExceptionSelectorRegister()) + FuncInfo->ExceptionSelectorVirtReg = MBB->addLiveIn(Reg, PtrRC); } /// isFoldedOrDeadInstruction - Return true if the specified instruction is @@ -970,6 +971,8 @@ void SelectionDAGISel::SelectAllBasicBlo FuncInfo->InsertPt = FuncInfo->MBB->getFirstNonPHI(); // Setup an EH landing-pad block. + FuncInfo->ExceptionPointerVirtReg = 0; + FuncInfo->ExceptionSelectorVirtReg = 0; if (FuncInfo->MBB->isLandingPad()) PrepareEHLandingPad();