Index: src/IceInstX8632.cpp |
diff --git a/src/IceInstX8632.cpp b/src/IceInstX8632.cpp |
index b4e597292a4712f92ba78694ba3495cc4e7640a5..aa2cdb70e299895e24056cff1596de80d30060c7 100644 |
--- a/src/IceInstX8632.cpp |
+++ b/src/IceInstX8632.cpp |
@@ -101,6 +101,20 @@ MachineTraits<TargetX8632>::X86OperandMem::X86OperandMem( |
void MachineTraits<TargetX8632>::X86OperandMem::emit(const Cfg *Func) const { |
if (!BuildDefs::dump()) |
return; |
+ const ::Ice::TargetLowering *Target = Func->getTarget(); |
+ // If the base is rematerializable, we need to replace it with the correct |
+ // physical register (esp or ebp), and update the Offset. |
+ int32_t Disp = 0; |
+ if (Base && Base->isRematerializable()) { |
+ Disp += Base->getStackOffset(); |
+ if (!getIgnoreStackAdjust()) |
+ Disp += Target->getStackAdjustment(); |
+ } |
+ // The index should never be rematerializable. But if we ever allow it, then |
+ // we should make sure the rematerialization offset is shifted by the Shift |
+ // value. |
+ if (Index) |
+ assert(!Index->isRematerializable()); |
Ostream &Str = Func->getContext()->getStrEmit(); |
if (SegmentReg != DefaultSegment) { |
assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); |
@@ -108,13 +122,17 @@ void MachineTraits<TargetX8632>::X86OperandMem::emit(const Cfg *Func) const { |
} |
// Emit as Offset(Base,Index,1<<Shift). Offset is emitted without the leading |
// '$'. Omit the (Base,Index,1<<Shift) part if Base==nullptr. |
- if (!Offset) { |
+ if (!Offset && Disp == 0) { |
Jim Stichnoth
2015/11/11 17:39:44
Offset == 0
sehr
2015/11/11 22:14:10
Done.
|
// No offset, emit nothing. |
+ } else if (!Offset && Disp != 0) { |
Jim Stichnoth
2015/11/11 17:39:44
Offset != 0
sehr
2015/11/11 22:14:10
I think you mean Offset == 0. Done, if so.
|
+ Str << Disp; |
} else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { |
- if (Base == nullptr || CI->getValue()) |
+ if (Base == nullptr || CI->getValue() || Disp) |
Jim Stichnoth
2015/11/11 17:39:44
Disp != 0
sehr
2015/11/11 22:14:10
Done.
|
// Emit a non-zero offset without a leading '$'. |
- Str << CI->getValue(); |
+ Str << CI->getValue() + Disp; |
} else if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { |
+ // TODO(sehr): this still needs updating for Disp. |
+ assert(Disp == 0); |
CR->emitWithoutPrefix(Func->getTarget()); |
} else { |
llvm_unreachable("Invalid offset type for x86 mem operand"); |
@@ -144,6 +162,12 @@ void MachineTraits<TargetX8632>::X86OperandMem::dump(const Cfg *Func, |
} |
bool Dumped = false; |
Str << "["; |
+ int32_t Disp = 0; |
+ if (Base && Base->isRematerializable()) { |
+ Disp += Base->getStackOffset(); |
+ if (!getIgnoreStackAdjust()) |
+ Disp += Func->getTarget()->getStackAdjustment(); |
+ } |
if (Base) { |
if (Func) |
Base->dump(Func); |
@@ -152,6 +176,7 @@ void MachineTraits<TargetX8632>::X86OperandMem::dump(const Cfg *Func, |
Dumped = true; |
} |
if (Index) { |
+ assert(!Index->isRematerializable()); |
if (Base) |
Str << "+"; |
if (Shift > 0) |
@@ -165,13 +190,16 @@ void MachineTraits<TargetX8632>::X86OperandMem::dump(const Cfg *Func, |
// Pretty-print the Offset. |
bool OffsetIsZero = false; |
bool OffsetIsNegative = false; |
- if (!Offset) { |
+ if (!Offset && Disp == 0) { |
Jim Stichnoth
2015/11/11 17:39:44
The same Offset==0 etc. as above.
sehr
2015/11/11 22:14:10
Done.
|
OffsetIsZero = true; |
+ } else if (!Offset && Disp != 0) { |
+ OffsetIsZero = (Disp == 0); |
+ OffsetIsNegative = (Disp < 0); |
} else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { |
- OffsetIsZero = (CI->getValue() == 0); |
- OffsetIsNegative = (static_cast<int32_t>(CI->getValue()) < 0); |
+ OffsetIsZero = (CI->getValue() + Disp == 0); |
+ OffsetIsNegative = (static_cast<int32_t>(CI->getValue()) + Disp < 0); |
} else { |
- assert(llvm::isa<ConstantRelocatable>(Offset)); |
+ assert(llvm::isa<ConstantRelocatable>(Offset) && Disp == 0); |
} |
if (Dumped) { |
if (!OffsetIsZero) { // Suppress if Offset is known to be 0 |
@@ -196,16 +224,25 @@ void MachineTraits<TargetX8632>::X86OperandMem::emitSegmentOverride( |
MachineTraits<TargetX8632>::Address |
MachineTraits<TargetX8632>::X86OperandMem::toAsmAddress( |
- MachineTraits<TargetX8632>::Assembler *Asm) const { |
+ MachineTraits<TargetX8632>::Assembler *Asm, |
+ Ice::TargetLowering *Target) const { |
int32_t Disp = 0; |
+ if (getBase() && getBase()->isRematerializable()) { |
+ Disp += getBase()->getStackOffset(); |
+ if (!getIgnoreStackAdjust()) { |
+ Disp += Target->getStackAdjustment(); |
+ } |
+ } |
+ if (getIndex()) |
Jim Stichnoth
2015/11/11 17:39:44
Add the same comment as in emit() ?
sehr
2015/11/11 22:14:10
Done.
|
+ assert(!getIndex()->isRematerializable()); |
AssemblerFixup *Fixup = nullptr; |
// Determine the offset (is it relocatable?) |
if (getOffset()) { |
if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { |
- Disp = static_cast<int32_t>(CI->getValue()); |
+ Disp += static_cast<int32_t>(CI->getValue()); |
} else if (const auto CR = |
llvm::dyn_cast<ConstantRelocatable>(getOffset())) { |
- Disp = CR->getOffset(); |
+ Disp += CR->getOffset(); |
Fixup = Asm->createFixup(RelFixup, CR); |
} else { |
llvm_unreachable("Unexpected offset type"); |