1 Pull in r199014 from upstream llvm trunk (by Venkatraman Govindaraju):
3 [Sparc] Bundle instruction with delay slow and its filler. Now, we can use -verify-machineinstrs with SPARC backend.
5 Introduced here: http://svnweb.freebsd.org/changeset/base/262261
7 Index: lib/Target/Sparc/DelaySlotFiller.cpp
8 ===================================================================
9 --- lib/Target/Sparc/DelaySlotFiller.cpp
10 +++ lib/Target/Sparc/DelaySlotFiller.cpp
12 #include "llvm/ADT/Statistic.h"
13 #include "llvm/CodeGen/MachineFunctionPass.h"
14 #include "llvm/CodeGen/MachineInstrBuilder.h"
15 +#include "llvm/CodeGen/MachineRegisterInfo.h"
16 #include "llvm/Support/CommandLine.h"
17 #include "llvm/Target/TargetInstrInfo.h"
18 #include "llvm/Target/TargetMachine.h"
19 @@ -55,6 +56,11 @@ namespace {
20 bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
21 bool runOnMachineFunction(MachineFunction &F) {
24 + // This pass invalidates liveness information when it reorders
25 + // instructions to fill delay slot.
26 + F.getRegInfo().invalidateLiveness();
28 for (MachineFunction::iterator FI = F.begin(), FE = F.end();
30 Changed |= runOnMachineBasicBlock(*FI);
31 @@ -61,9 +67,6 @@ namespace {
35 - bool isDelayFiller(MachineBasicBlock &MBB,
36 - MachineBasicBlock::iterator candidate);
38 void insertCallDefsUses(MachineBasicBlock::iterator MI,
39 SmallSet<unsigned, 32>& RegDefs,
40 SmallSet<unsigned, 32>& RegUses);
41 @@ -152,6 +155,10 @@ bool Filler::runOnMachineBasicBlock(MachineBasicBl
42 assert (J != MBB.end() && "MI needs a delay instruction.");
43 BuildMI(MBB, ++J, MI->getDebugLoc(),
44 TII->get(SP::UNIMP)).addImm(structSize);
45 + // Bundle the delay filler and unimp with the instruction.
46 + MIBundleBuilder(MBB, MachineBasicBlock::iterator(MI), J);
48 + MIBundleBuilder(MBB, MachineBasicBlock::iterator(MI), I);
52 @@ -209,7 +216,7 @@ Filler::findDelayInstr(MachineBasicBlock &MBB,
56 - || isDelayFiller(MBB, I))
57 + || I->isBundledWithSucc())
60 if (delayHasHazard(I, sawLoad, sawStore, RegDefs, RegUses)) {
61 @@ -332,18 +339,6 @@ bool Filler::IsRegInSet(SmallSet<unsigned, 32>& Re
65 -// return true if the candidate is a delay filler.
66 -bool Filler::isDelayFiller(MachineBasicBlock &MBB,
67 - MachineBasicBlock::iterator candidate)
69 - if (candidate == MBB.begin())
71 - if (candidate->getOpcode() == SP::UNIMP)
74 - return candidate->hasDelaySlot();
77 bool Filler::needsUnimp(MachineBasicBlock::iterator I, unsigned &StructSize)
80 @@ -484,10 +479,10 @@ bool Filler::tryCombineRestoreWithPrevInst(Machine
81 && MBBI->getOperand(1).getReg() == SP::G0
82 && MBBI->getOperand(2).getReg() == SP::G0);
84 - MachineBasicBlock::iterator PrevInst = MBBI; --PrevInst;
85 + MachineBasicBlock::iterator PrevInst = llvm::prior(MBBI);
87 - // It cannot combine with a delay filler.
88 - if (isDelayFiller(MBB, PrevInst))
89 + // It cannot be combined with a bundled instruction.
90 + if (PrevInst->isBundledWithSucc())
93 const TargetInstrInfo *TII = TM.getInstrInfo();
94 Index: lib/Target/Sparc/SparcAsmPrinter.cpp
95 ===================================================================
96 --- lib/Target/Sparc/SparcAsmPrinter.cpp
97 +++ lib/Target/Sparc/SparcAsmPrinter.cpp
98 @@ -184,7 +184,6 @@ static void LowerGETPCXAndEmitMCInsts(const Machin
100 void SparcAsmPrinter::EmitInstruction(const MachineInstr *MI)
104 switch (MI->getOpcode()) {
106 @@ -195,8 +194,13 @@ void SparcAsmPrinter::EmitInstruction(const Machin
107 LowerGETPCXAndEmitMCInsts(MI, OutStreamer, OutContext);
110 - LowerSparcMachineInstrToMCInst(MI, TmpInst, *this);
111 - OutStreamer.EmitInstruction(TmpInst);
112 + MachineBasicBlock::const_instr_iterator I = MI;
113 + MachineBasicBlock::const_instr_iterator E = MI->getParent()->instr_end();
116 + LowerSparcMachineInstrToMCInst(I, TmpInst, *this);
117 + OutStreamer.EmitInstruction(TmpInst);
118 + } while ((++I != E) && I->isInsideBundle()); // Delay slot check.
121 void SparcAsmPrinter::EmitFunctionBodyStart() {
122 Index: test/CodeGen/SPARC/2011-01-19-DelaySlot.ll
123 ===================================================================
124 --- test/CodeGen/SPARC/2011-01-19-DelaySlot.ll
125 +++ test/CodeGen/SPARC/2011-01-19-DelaySlot.ll
127 -;RUN: llc -march=sparc < %s | FileCheck %s
128 -;RUN: llc -march=sparc -O0 < %s | FileCheck %s -check-prefix=UNOPT
129 +;RUN: llc -march=sparc < %s -verify-machineinstrs | FileCheck %s
130 +;RUN: llc -march=sparc -O0 < %s -verify-machineinstrs | FileCheck %s -check-prefix=UNOPT
133 define i32 @test(i32 %a) nounwind {