[llvm-commits] [llvm] r107227 - in /llvm/trunk: include/llvm/CodeGen/MachineRegisterInfo.h lib/CodeGen/CMakeLists.txt lib/CodeGen/InlineSpiller.cpp lib/CodeGen/Spiller.cpp
Evan Cheng
evan.cheng at apple.com
Tue Jun 29 18:05:26 PDT 2010
On Jun 29, 2010, at 4:58 PM, Jakob Stoklund Olesen wrote:
> Author: stoklund
> Date: Tue Jun 29 18:58:39 2010
> New Revision: 107227
>
> URL: http://llvm.org/viewvc/llvm-project?rev=107227&view=rev
> Log:
> Begin implementation of an inline spiller.
>
> InlineSpiller inserts loads and spills immediately instead of deferring to
> VirtRegMap. This is possible now because SlotIndexes allows instructions to be
> inserted and renumbered.
>
> This is work in progress, and is mostly a copy of TrivialSpiller so far. It
> works very well for functions that don't require spilling.
Sounds like we should switch over now! :-)
Evan
>
> Added:
> llvm/trunk/lib/CodeGen/InlineSpiller.cpp
> Modified:
> llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h
> llvm/trunk/lib/CodeGen/CMakeLists.txt
> llvm/trunk/lib/CodeGen/Spiller.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h?rev=107227&r1=107226&r2=107227&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h Tue Jun 29 18:58:39 2010
> @@ -363,7 +363,18 @@
> defusechain_iterator operator++(int) { // Postincrement
> defusechain_iterator tmp = *this; ++*this; return tmp;
> }
> -
> +
> + /// skipInstruction - move forward until reaching a different instruction.
> + /// Return the skipped instruction that is no longer pointed to, or NULL if
> + /// already pointing to end().
> + MachineInstr *skipInstruction() {
> + if (!Op) return 0;
> + MachineInstr *MI = Op->getParent();
> + do ++*this;
> + while (Op && Op->getParent() == MI);
> + return MI;
> + }
> +
> MachineOperand &getOperand() const {
> assert(Op && "Cannot dereference end iterator!");
> return *Op;
>
> Modified: llvm/trunk/lib/CodeGen/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CMakeLists.txt?rev=107227&r1=107226&r2=107227&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/CMakeLists.txt (original)
> +++ llvm/trunk/lib/CodeGen/CMakeLists.txt Tue Jun 29 18:58:39 2010
> @@ -13,6 +13,7 @@
> GCMetadataPrinter.cpp
> GCStrategy.cpp
> IfConversion.cpp
> + InlineSpiller.cpp
> IntrinsicLowering.cpp
> LLVMTargetMachine.cpp
> LatencyPriorityQueue.cpp
>
> Added: llvm/trunk/lib/CodeGen/InlineSpiller.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/InlineSpiller.cpp?rev=107227&view=auto
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/InlineSpiller.cpp (added)
> +++ llvm/trunk/lib/CodeGen/InlineSpiller.cpp Tue Jun 29 18:58:39 2010
> @@ -0,0 +1,136 @@
> +//===-------- InlineSpiller.cpp - Insert spills and restores inline -------===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// The inline spiller modifies the machine function directly instead of
> +// inserting spills and restores in VirtRegMap.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#define DEBUG_TYPE "spiller"
> +#include "Spiller.h"
> +#include "VirtRegMap.h"
> +#include "llvm/CodeGen/LiveIntervalAnalysis.h"
> +#include "llvm/CodeGen/MachineFrameInfo.h"
> +#include "llvm/CodeGen/MachineFunction.h"
> +#include "llvm/CodeGen/MachineRegisterInfo.h"
> +#include "llvm/Target/TargetMachine.h"
> +#include "llvm/Target/TargetInstrInfo.h"
> +#include "llvm/Support/Debug.h"
> +#include "llvm/Support/raw_ostream.h"
> +
> +using namespace llvm;
> +
> +namespace {
> +class InlineSpiller : public Spiller {
> + MachineFunction &mf_;
> + LiveIntervals &lis_;
> + VirtRegMap &vrm_;
> + MachineFrameInfo &mfi_;
> + MachineRegisterInfo &mri_;
> + const TargetInstrInfo &tii_;
> + const TargetRegisterInfo &tri_;
> +
> + ~InlineSpiller() {}
> +
> +public:
> + InlineSpiller(MachineFunction *mf, LiveIntervals *lis, VirtRegMap *vrm)
> + : mf_(*mf), lis_(*lis), vrm_(*vrm),
> + mfi_(*mf->getFrameInfo()),
> + mri_(mf->getRegInfo()),
> + tii_(*mf->getTarget().getInstrInfo()),
> + tri_(*mf->getTarget().getRegisterInfo()) {}
> +
> + void spill(LiveInterval *li,
> + std::vector<LiveInterval*> &newIntervals,
> + SmallVectorImpl<LiveInterval*> &spillIs,
> + SlotIndex *earliestIndex);
> +};
> +}
> +
> +namespace llvm {
> +Spiller *createInlineSpiller(MachineFunction *mf,
> + LiveIntervals *lis,
> + const MachineLoopInfo *mli,
> + VirtRegMap *vrm) {
> + return new InlineSpiller(mf, lis, vrm);
> +}
> +}
> +
> +void InlineSpiller::spill(LiveInterval *li,
> + std::vector<LiveInterval*> &newIntervals,
> + SmallVectorImpl<LiveInterval*> &spillIs,
> + SlotIndex *earliestIndex) {
> + DEBUG(dbgs() << "Inline spilling " << *li << "\n");
> + assert(li->isSpillable() && "Attempting to spill already spilled value.");
> + assert(!li->isStackSlot() && "Trying to spill a stack slot.");
> +
> + const TargetRegisterClass *RC = mri_.getRegClass(li->reg);
> + unsigned SS = vrm_.assignVirt2StackSlot(li->reg);
> +
> + for (MachineRegisterInfo::reg_iterator RI = mri_.reg_begin(li->reg);
> + MachineInstr *MI = RI.skipInstruction();) {
> + SlotIndex Idx = lis_.getInstructionIndex(MI).getDefIndex();
> +
> + // Analyze instruction.
> + bool Reads, Writes;
> + SmallVector<unsigned, 8> Ops;
> + tie(Reads, Writes) = MI->readsWritesVirtualRegister(li->reg, &Ops);
> +
> + // Allocate interval around instruction.
> + // FIXME: Infer regclass from instruction alone.
> + unsigned NewVReg = mri_.createVirtualRegister(RC);
> + vrm_.grow();
> + LiveInterval &NewLI = lis_.getOrCreateInterval(NewVReg);
> + NewLI.markNotSpillable();
> +
> + // Reload if instruction reads register.
> + if (Reads) {
> + MachineBasicBlock::iterator MII = MI;
> + tii_.loadRegFromStackSlot(*MI->getParent(), MII, NewVReg, SS, RC, &tri_);
> + --MII; // Point to load instruction.
> + SlotIndex LoadIdx = lis_.InsertMachineInstrInMaps(MII).getDefIndex();
> + DEBUG(dbgs() << "\treload: " << LoadIdx << '\t' << *MII);
> + VNInfo *LoadVNI = NewLI.getNextValue(LoadIdx, 0, true,
> + lis_.getVNInfoAllocator());
> + NewLI.addRange(LiveRange(LoadIdx, Idx, LoadVNI));
> + }
> +
> + // Rewrite instruction operands.
> + bool hasLiveDef = false;
> + for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
> + MachineOperand &MO = MI->getOperand(Ops[i]);
> + MO.setReg(NewVReg);
> + if (MO.isUse()) {
> + if (!MI->isRegTiedToDefOperand(Ops[i]))
> + MO.setIsKill();
> + } else {
> + if (!MO.isDead())
> + hasLiveDef = true;
> + }
> + }
> + DEBUG(dbgs() << "\trewrite: " << Idx << '\t' << *MI);
> +
> + // Spill is instruction writes register.
> + // FIXME: Use a second vreg if instruction has no tied ops.
> + if (Writes && hasLiveDef) {
> + MachineBasicBlock::iterator MII = MI;
> + tii_.storeRegToStackSlot(*MI->getParent(), ++MII, NewVReg, true, SS, RC,
> + &tri_);
> + --MII; // Point to store instruction.
> + SlotIndex StoreIdx = lis_.InsertMachineInstrInMaps(MII).getDefIndex();
> + DEBUG(dbgs() << "\tspilled: " << StoreIdx << '\t' << *MII);
> + VNInfo *StoreVNI = NewLI.getNextValue(Idx, 0, true,
> + lis_.getVNInfoAllocator());
> + NewLI.addRange(LiveRange(Idx, StoreIdx, StoreVNI));
> + }
> +
> + DEBUG(dbgs() << "\tinterval: " << NewLI << '\n');
> + newIntervals.push_back(&NewLI);
> + }
> +}
>
> Modified: llvm/trunk/lib/CodeGen/Spiller.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Spiller.cpp?rev=107227&r1=107226&r2=107227&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/Spiller.cpp (original)
> +++ llvm/trunk/lib/CodeGen/Spiller.cpp Tue Jun 29 18:58:39 2010
> @@ -26,7 +26,7 @@
> using namespace llvm;
>
> namespace {
> - enum SpillerName { trivial, standard, splitting };
> + enum SpillerName { trivial, standard, splitting, inline_ };
> }
>
> static cl::opt<SpillerName>
> @@ -36,6 +36,7 @@
> cl::values(clEnumVal(trivial, "trivial spiller"),
> clEnumVal(standard, "default spiller"),
> clEnumVal(splitting, "splitting spiller"),
> + "inline", inline_, "inline spiller",
> clEnumValEnd),
> cl::init(standard));
>
> @@ -506,6 +507,13 @@
> } // end anonymous namespace
>
>
> +namespace llvm {
> +Spiller *createInlineSpiller(MachineFunction*,
> + LiveIntervals*,
> + const MachineLoopInfo*,
> + VirtRegMap*);
> +}
> +
> llvm::Spiller* llvm::createSpiller(MachineFunction *mf, LiveIntervals *lis,
> const MachineLoopInfo *loopInfo,
> VirtRegMap *vrm) {
> @@ -514,5 +522,6 @@
> case trivial: return new TrivialSpiller(mf, lis, vrm);
> case standard: return new StandardSpiller(lis, loopInfo, vrm);
> case splitting: return new SplittingSpiller(mf, lis, loopInfo, vrm);
> + case inline_: return createInlineSpiller(mf, lis, loopInfo, vrm);
> }
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list