[llvm-branch-commits] [llvm-branch] r92887 - in /llvm/branches/Apple/Zoidberg: include/llvm/CodeGen/MachineFunction.h include/llvm/Target/TargetInstrInfo.h lib/CodeGen/TailDuplication.cpp lib/CodeGen/TargetInstrInfoImpl.cpp lib/Target/ARM/ARMBaseInstrInfo.cpp lib/Target/ARM/ARMBaseInstrInfo.h test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll
Jakob Stoklund Olesen
stoklund at 2pi.dk
Wed Jan 6 17:08:19 PST 2010
Author: stoklund
Date: Wed Jan 6 19:08:18 2010
New Revision: 92887
URL: http://llvm.org/viewvc/llvm-project?rev=92887&view=rev
Log:
$ svn merge -c 92873 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r92873 into '.':
A test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll
U include/llvm/Target/TargetInstrInfo.h
U lib/CodeGen/TargetInstrInfoImpl.cpp
U lib/CodeGen/TailDuplication.cpp
U lib/Target/ARM/ARMBaseInstrInfo.cpp
U lib/Target/ARM/ARMBaseInstrInfo.h
$ svn merge -c 92883 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r92883 into '.':
U test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll
G include/llvm/Target/TargetInstrInfo.h
U include/llvm/CodeGen/MachineFunction.h
Added:
llvm/branches/Apple/Zoidberg/test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll
- copied, changed from r92873, llvm/trunk/test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll
Modified:
llvm/branches/Apple/Zoidberg/include/llvm/CodeGen/MachineFunction.h
llvm/branches/Apple/Zoidberg/include/llvm/Target/TargetInstrInfo.h
llvm/branches/Apple/Zoidberg/lib/CodeGen/TailDuplication.cpp
llvm/branches/Apple/Zoidberg/lib/CodeGen/TargetInstrInfoImpl.cpp
llvm/branches/Apple/Zoidberg/lib/Target/ARM/ARMBaseInstrInfo.cpp
llvm/branches/Apple/Zoidberg/lib/Target/ARM/ARMBaseInstrInfo.h
Modified: llvm/branches/Apple/Zoidberg/include/llvm/CodeGen/MachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/include/llvm/CodeGen/MachineFunction.h?rev=92887&r1=92886&r2=92887&view=diff
==============================================================================
--- llvm/branches/Apple/Zoidberg/include/llvm/CodeGen/MachineFunction.h (original)
+++ llvm/branches/Apple/Zoidberg/include/llvm/CodeGen/MachineFunction.h Wed Jan 6 19:08:18 2010
@@ -315,6 +315,8 @@
/// 'Orig' instruction, identical in all ways except the the instruction
/// has no parent, prev, or next.
///
+ /// See also TargetInstrInfo::duplicate() for target-specific fixes to cloned
+ /// instructions.
MachineInstr *CloneMachineInstr(const MachineInstr *Orig);
/// DeleteMachineInstr - Delete the given MachineInstr.
Modified: llvm/branches/Apple/Zoidberg/include/llvm/Target/TargetInstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/include/llvm/Target/TargetInstrInfo.h?rev=92887&r1=92886&r2=92887&view=diff
==============================================================================
--- llvm/branches/Apple/Zoidberg/include/llvm/Target/TargetInstrInfo.h (original)
+++ llvm/branches/Apple/Zoidberg/include/llvm/Target/TargetInstrInfo.h Wed Jan 6 19:08:18 2010
@@ -228,6 +228,14 @@
const MachineInstr *Orig,
const TargetRegisterInfo *TRI) const = 0;
+ /// duplicate - Create a duplicate of the Orig instruction in MF. This is like
+ /// MachineFunction::CloneMachineInstr(), but the target may update operands
+ /// that are required to be unique.
+ ///
+ /// The instruction must be duplicable as indicated by isNotDuplicable().
+ virtual MachineInstr *duplicate(MachineInstr *Orig,
+ MachineFunction &MF) const = 0;
+
/// convertToThreeAddress - This method must be implemented by targets that
/// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
/// may be able to convert a two-address instruction into one or more true
@@ -557,6 +565,8 @@
unsigned DestReg, unsigned SubReg,
const MachineInstr *Orig,
const TargetRegisterInfo *TRI) const;
+ virtual MachineInstr *duplicate(MachineInstr *Orig,
+ MachineFunction &MF) const;
virtual bool isIdentical(const MachineInstr *MI,
const MachineInstr *Other,
const MachineRegisterInfo *MRI) const;
Modified: llvm/branches/Apple/Zoidberg/lib/CodeGen/TailDuplication.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/CodeGen/TailDuplication.cpp?rev=92887&r1=92886&r2=92887&view=diff
==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/CodeGen/TailDuplication.cpp (original)
+++ llvm/branches/Apple/Zoidberg/lib/CodeGen/TailDuplication.cpp Wed Jan 6 19:08:18 2010
@@ -346,7 +346,7 @@
MachineBasicBlock *PredBB,
MachineFunction &MF,
DenseMap<unsigned, unsigned> &LocalVRMap) {
- MachineInstr *NewMI = MF.CloneMachineInstr(MI);
+ MachineInstr *NewMI = TII->duplicate(MI, MF);
for (unsigned i = 0, e = NewMI->getNumOperands(); i != e; ++i) {
MachineOperand &MO = NewMI->getOperand(i);
if (!MO.isReg())
Modified: llvm/branches/Apple/Zoidberg/lib/CodeGen/TargetInstrInfoImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/CodeGen/TargetInstrInfoImpl.cpp?rev=92887&r1=92886&r2=92887&view=diff
==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/CodeGen/TargetInstrInfoImpl.cpp (original)
+++ llvm/branches/Apple/Zoidberg/lib/CodeGen/TargetInstrInfoImpl.cpp Wed Jan 6 19:08:18 2010
@@ -150,6 +150,13 @@
MBB.insert(I, MI);
}
+MachineInstr *TargetInstrInfoImpl::duplicate(MachineInstr *Orig,
+ MachineFunction &MF) const {
+ assert(!Orig->getDesc().isNotDuplicable() &&
+ "Instruction cannot be duplicated");
+ return MF.CloneMachineInstr(Orig);
+}
+
bool
TargetInstrInfoImpl::isIdentical(const MachineInstr *MI,
const MachineInstr *Other,
Modified: llvm/branches/Apple/Zoidberg/lib/Target/ARM/ARMBaseInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/Target/ARM/ARMBaseInstrInfo.cpp?rev=92887&r1=92886&r2=92887&view=diff
==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/Target/ARM/ARMBaseInstrInfo.cpp (original)
+++ llvm/branches/Apple/Zoidberg/lib/Target/ARM/ARMBaseInstrInfo.cpp Wed Jan 6 19:08:18 2010
@@ -937,6 +937,35 @@
return false;
}
+/// Create a copy of a const pool value. Update CPI to the new index and return
+/// the label UID.
+static unsigned duplicateCPV(MachineFunction &MF, unsigned &CPI) {
+ MachineConstantPool *MCP = MF.getConstantPool();
+ ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
+
+ const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPI];
+ assert(MCPE.isMachineConstantPoolEntry() &&
+ "Expecting a machine constantpool entry!");
+ ARMConstantPoolValue *ACPV =
+ static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal);
+
+ unsigned PCLabelId = AFI->createConstPoolEntryUId();
+ ARMConstantPoolValue *NewCPV = 0;
+ if (ACPV->isGlobalValue())
+ NewCPV = new ARMConstantPoolValue(ACPV->getGV(), PCLabelId,
+ ARMCP::CPValue, 4);
+ else if (ACPV->isExtSymbol())
+ NewCPV = new ARMConstantPoolValue(MF.getFunction()->getContext(),
+ ACPV->getSymbol(), PCLabelId, 4);
+ else if (ACPV->isBlockAddress())
+ NewCPV = new ARMConstantPoolValue(ACPV->getBlockAddress(), PCLabelId,
+ ARMCP::CPBlockAddress, 4);
+ else
+ llvm_unreachable("Unexpected ARM constantpool value type!!");
+ CPI = MCP->getConstantPoolIndex(NewCPV, MCPE.getAlignment());
+ return PCLabelId;
+}
+
void ARMBaseInstrInfo::
reMaterialize(MachineBasicBlock &MBB,
MachineBasicBlock::iterator I,
@@ -961,28 +990,8 @@
case ARM::tLDRpci_pic:
case ARM::t2LDRpci_pic: {
MachineFunction &MF = *MBB.getParent();
- ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
- MachineConstantPool *MCP = MF.getConstantPool();
unsigned CPI = Orig->getOperand(1).getIndex();
- const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPI];
- assert(MCPE.isMachineConstantPoolEntry() &&
- "Expecting a machine constantpool entry!");
- ARMConstantPoolValue *ACPV =
- static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal);
- unsigned PCLabelId = AFI->createConstPoolEntryUId();
- ARMConstantPoolValue *NewCPV = 0;
- if (ACPV->isGlobalValue())
- NewCPV = new ARMConstantPoolValue(ACPV->getGV(), PCLabelId,
- ARMCP::CPValue, 4);
- else if (ACPV->isExtSymbol())
- NewCPV = new ARMConstantPoolValue(MF.getFunction()->getContext(),
- ACPV->getSymbol(), PCLabelId, 4);
- else if (ACPV->isBlockAddress())
- NewCPV = new ARMConstantPoolValue(ACPV->getBlockAddress(), PCLabelId,
- ARMCP::CPBlockAddress, 4);
- else
- llvm_unreachable("Unexpected ARM constantpool value type!!");
- CPI = MCP->getConstantPoolIndex(NewCPV, MCPE.getAlignment());
+ unsigned PCLabelId = duplicateCPV(MF, CPI);
MachineInstrBuilder MIB = BuildMI(MBB, I, Orig->getDebugLoc(), get(Opcode),
DestReg)
.addConstantPoolIndex(CPI).addImm(PCLabelId);
@@ -995,6 +1004,22 @@
NewMI->getOperand(0).setSubReg(SubIdx);
}
+MachineInstr *
+ARMBaseInstrInfo::duplicate(MachineInstr *Orig, MachineFunction &MF) const {
+ MachineInstr *MI = TargetInstrInfoImpl::duplicate(Orig, MF);
+ switch(Orig->getOpcode()) {
+ case ARM::tLDRpci_pic:
+ case ARM::t2LDRpci_pic: {
+ unsigned CPI = Orig->getOperand(1).getIndex();
+ unsigned PCLabelId = duplicateCPV(MF, CPI);
+ Orig->getOperand(1).setIndex(CPI);
+ Orig->getOperand(2).setImm(PCLabelId);
+ break;
+ }
+ }
+ return MI;
+}
+
bool ARMBaseInstrInfo::isIdentical(const MachineInstr *MI0,
const MachineInstr *MI1,
const MachineRegisterInfo *MRI) const {
Modified: llvm/branches/Apple/Zoidberg/lib/Target/ARM/ARMBaseInstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/Target/ARM/ARMBaseInstrInfo.h?rev=92887&r1=92886&r2=92887&view=diff
==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/Target/ARM/ARMBaseInstrInfo.h (original)
+++ llvm/branches/Apple/Zoidberg/lib/Target/ARM/ARMBaseInstrInfo.h Wed Jan 6 19:08:18 2010
@@ -274,6 +274,8 @@
const MachineInstr *Orig,
const TargetRegisterInfo *TRI) const;
+ MachineInstr *duplicate(MachineInstr *Orig, MachineFunction &MF) const;
+
virtual bool isIdentical(const MachineInstr *MI, const MachineInstr *Other,
const MachineRegisterInfo *MRI) const;
};
Copied: llvm/branches/Apple/Zoidberg/test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll (from r92873, llvm/trunk/test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll?p2=llvm/branches/Apple/Zoidberg/test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll&p1=llvm/trunk/test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll&r1=92873&r2=92887&rev=92887&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll (original)
+++ llvm/branches/Apple/Zoidberg/test/CodeGen/Thumb2/2010-01-06-TailDuplicateLabels.ll Wed Jan 6 19:08:18 2010
@@ -2,6 +2,8 @@
target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:32-n32"
target triple = "thumbv7-apple-darwin10"
+; This function produces a duplicate LPC label unless special care is taken when duplicating a t2LDRpci_pic instruction.
+
%struct.PlatformMutex = type { i32, [40 x i8] }
%struct.SpinLock = type { %struct.PlatformMutex }
%"struct.WTF::TCMalloc_ThreadCache" = type { i32, %struct._opaque_pthread_t*, i8, [68 x %"struct.WTF::TCMalloc_ThreadCache_FreeList"], i32, i32, %"struct.WTF::TCMalloc_ThreadCache"*, %"struct.WTF::TCMalloc_ThreadCache"* }
More information about the llvm-branch-commits
mailing list