Commit 523ef721 by Jim Stichnoth

Subzero: Work around another llvm-mc parser bug for relocatable symbols.

There's already a hack that emits asm like: lea eax, myglobal instead of: mov eax, [myglobal] because of an llvm-mc parser bug. However, the lea hack still doesn't work if the symbol is a reserved word, e.g.: lea eax, flags The extra hack is to drop into AT&T syntax temporarily: .att_syntax leal flags, %eax .intel_syntax BUG= none R=jvoung@chromium.org Review URL: https://codereview.chromium.org/543803002
parent dd7b846c
......@@ -968,16 +968,22 @@ template <> void InstX8632Mov::emit(const Cfg *Func) const {
// The llvm-mc assembler using Intel syntax has a bug in which "mov
// reg, RelocatableConstant" does not generate the right instruction
// with a relocation. To work around, we emit "lea reg,
// [RelocatableConstant]". Also, the lowering and legalization is
// RelocatableConstant". Also, the lowering and legalization is
// changed to allow relocatable constants only in Assign and Call
// instructions or in Mem operands. TODO(stichnot): remove LEAHACK
// once a proper emitter is used.
//
// In addition, llvm-mc doesn't like "lea eax, bp" or "lea eax, Sp"
// or "lea eax, flags" etc., when the relocatable constant name is a
// reserved word. The hack-on-top-of-hack is to temporarily drop
// into AT&T syntax for this lea instruction.
bool UseLeaHack = llvm::isa<ConstantRelocatable>(Src);
Str << "\t";
if (UseLeaHack)
Str << "lea";
else
Str << "mov" << TypeX8632Attributes[getDest()->getType()].SdSsString;
if (UseLeaHack) {
Str << ".att_syntax\n";
Str << "\tleal";
} else {
Str << "\tmov" << TypeX8632Attributes[getDest()->getType()].SdSsString;
}
Str << "\t";
// For an integer truncation operation, src is wider than dest.
// Ideally, we use a mov instruction whose data width matches the
......@@ -991,10 +997,18 @@ template <> void InstX8632Mov::emit(const Cfg *Func) const {
// Clean this up.
assert(Func->getTarget()->typeWidthInBytesOnStack(getDest()->getType()) ==
Func->getTarget()->typeWidthInBytesOnStack(Src->getType()));
getDest()->asType(Src->getType()).emit(Func);
Str << ", ";
Src->emit(Func);
Str << "\n";
if (UseLeaHack) {
Src->emit(Func);
Str << ", %";
getDest()->emit(Func);
Str << "\n";
Str << ".intel_syntax\n";
} else {
getDest()->asType(Src->getType()).emit(Func);
Str << ", ";
Src->emit(Func);
Str << "\n";
}
}
template <> void InstX8632Movp::emit(const Cfg *Func) const {
......
......@@ -92,7 +92,28 @@ entry:
call void @use(i32 %expanded13)
ret i32 0
}
; CHECK: entry:
; CHECK-LABEL: main
; CHECK: .att_syntax
; CHECK: leal PrimitiveInit,
; CHECK: .intel_syntax
; CHECK: .att_syntax
; CHECK: leal PrimitiveInitConst,
; CHECK: .intel_syntax
; CHECK: .att_syntax
; CHECK: leal PrimitiveInitStatic,
; CHECK: .intel_syntax
; CHECK: .att_syntax
; CHECK: leal PrimitiveUninit,
; CHECK: .intel_syntax
; CHECK: .att_syntax
; CHECK: leal ArrayInit,
; CHECK: .intel_syntax
; CHECK: .att_syntax
; CHECK: leal ArrayInitPartial,
; CHECK: .intel_syntax
; CHECK: .att_syntax
; CHECK: leal ArrayUninit,
; CHECK: .intel_syntax
declare void @use(i32)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment