Commit 0b9eee52 by Jan Voung

emitIAS for push -- simplify push since it's not used for args passing anymore

Since push isn't used for args passing anymore, the cases of handling push for vectors and floats/doubles isn't needed anymore. Passing vectors requires a bit more care of alignment, so that was changed. I can imagine push needing to handle addresses later (at least on x86-64 to push the lower 32-bits of return address), but for now, this means only handling GPRs. The XMM registers are not callee saved. BUG=none R=stichnot@chromium.org Review URL: https://codereview.chromium.org/633553003
parent 037fa1d9
...@@ -305,10 +305,8 @@ InstX8632Fstp::InstX8632Fstp(Cfg *Func, Variable *Dest) ...@@ -305,10 +305,8 @@ InstX8632Fstp::InstX8632Fstp(Cfg *Func, Variable *Dest)
InstX8632Pop::InstX8632Pop(Cfg *Func, Variable *Dest) InstX8632Pop::InstX8632Pop(Cfg *Func, Variable *Dest)
: InstX8632(Func, InstX8632::Pop, 0, Dest) {} : InstX8632(Func, InstX8632::Pop, 0, Dest) {}
InstX8632Push::InstX8632Push(Cfg *Func, Operand *Source, InstX8632Push::InstX8632Push(Cfg *Func, Variable *Source)
bool SuppressStackAdjustment) : InstX8632(Func, InstX8632::Push, 1, NULL) {
: InstX8632(Func, InstX8632::Push, 1, NULL),
SuppressStackAdjustment(SuppressStackAdjustment) {
addSource(Source); addSource(Source);
} }
...@@ -2074,34 +2072,24 @@ void InstX8632AdjustStack::dump(const Cfg *Func) const { ...@@ -2074,34 +2072,24 @@ void InstX8632AdjustStack::dump(const Cfg *Func) const {
void InstX8632Push::emit(const Cfg *Func) const { void InstX8632Push::emit(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrEmit(); Ostream &Str = Func->getContext()->getStrEmit();
assert(getSrcSize() == 1); assert(getSrcSize() == 1);
Type Ty = getSrc(0)->getType(); // Push is currently only used for saving GPRs.
Variable *Var = llvm::dyn_cast<Variable>(getSrc(0)); Variable *Var = llvm::cast<Variable>(getSrc(0));
if ((isVectorType(Ty) || isScalarFloatingType(Ty)) && Var && Var->hasReg()) { assert(Var->hasReg());
// The xmm registers can't be directly pushed, so we fake it by
// decrementing esp and then storing to [esp].
Str << "\tsub\tesp, " << typeWidthInBytes(Ty) << "\n";
if (!SuppressStackAdjustment)
Func->getTarget()->updateStackAdjustment(typeWidthInBytes(Ty));
if (isVectorType(Ty)) {
Str << "\tmovups\txmmword ptr [esp], ";
} else {
Str << "\tmov" << TypeX8632Attributes[Ty].SdSsString << "\t"
<< TypeX8632Attributes[Ty].WidthString << " [esp], ";
}
getSrc(0)->emit(Func);
Str << "\n";
} else if (Ty == IceType_f64 && (!Var || !Var->hasReg())) {
// A double on the stack has to be pushed as two halves. Push the
// upper half followed by the lower half for little-endian. TODO:
// implement.
llvm_unreachable("Missing support for pushing doubles from memory");
} else {
Str << "\tpush\t"; Str << "\tpush\t";
getSrc(0)->emit(Func); Var->emit(Func);
Str << "\n"; Str << "\n";
if (!SuppressStackAdjustment) }
Func->getTarget()->updateStackAdjustment(4);
} void InstX8632Push::emitIAS(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrEmit();
assert(getSrcSize() == 1);
// Push is currently only used for saving GPRs.
Variable *Var = llvm::cast<Variable>(getSrc(0));
assert(Var->hasReg());
x86::AssemblerX86 *Asm = Func->getAssembler<x86::AssemblerX86>();
intptr_t StartPosition = Asm->GetPosition();
Asm->pushl(RegX8632::getEncodedGPR(Var->getRegNum()));
emitIASBytes(Str, Asm, StartPosition);
} }
void InstX8632Push::dump(const Cfg *Func) const { void InstX8632Push::dump(const Cfg *Func) const {
......
...@@ -1395,20 +1395,19 @@ private: ...@@ -1395,20 +1395,19 @@ private:
class InstX8632Push : public InstX8632 { class InstX8632Push : public InstX8632 {
public: public:
static InstX8632Push *create(Cfg *Func, Operand *Source, static InstX8632Push *create(Cfg *Func, Variable *Source) {
bool SuppressStackAdjustment) {
return new (Func->allocate<InstX8632Push>()) return new (Func->allocate<InstX8632Push>())
InstX8632Push(Func, Source, SuppressStackAdjustment); InstX8632Push(Func, Source);
} }
void emit(const Cfg *Func) const override; void emit(const Cfg *Func) const override;
void emitIAS(const Cfg *Func) const override;
void dump(const Cfg *Func) const override; void dump(const Cfg *Func) const override;
static bool classof(const Inst *Inst) { return isClassof(Inst, Push); } static bool classof(const Inst *Inst) { return isClassof(Inst, Push); }
private: private:
InstX8632Push(Cfg *Func, Operand *Source, bool SuppressStackAdjustment); InstX8632Push(Cfg *Func, Variable *Source);
InstX8632Push(const InstX8632Push &) = delete; InstX8632Push(const InstX8632Push &) = delete;
InstX8632Push &operator=(const InstX8632Push &) = delete; InstX8632Push &operator=(const InstX8632Push &) = delete;
bool SuppressStackAdjustment;
~InstX8632Push() override {} ~InstX8632Push() override {}
}; };
......
...@@ -748,8 +748,7 @@ void TargetX8632::addProlog(CfgNode *Node) { ...@@ -748,8 +748,7 @@ void TargetX8632::addProlog(CfgNode *Node) {
if (CalleeSaves[i] && RegsUsed[i]) { if (CalleeSaves[i] && RegsUsed[i]) {
++NumCallee; ++NumCallee;
PreservedRegsSizeBytes += 4; PreservedRegsSizeBytes += 4;
const bool SuppressStackAdjustment = true; _push(getPhysicalRegister(i));
_push(getPhysicalRegister(i), SuppressStackAdjustment);
} }
} }
Ctx->statsUpdateRegistersSaved(NumCallee); Ctx->statsUpdateRegistersSaved(NumCallee);
...@@ -761,8 +760,7 @@ void TargetX8632::addProlog(CfgNode *Node) { ...@@ -761,8 +760,7 @@ void TargetX8632::addProlog(CfgNode *Node) {
PreservedRegsSizeBytes += 4; PreservedRegsSizeBytes += 4;
Variable *ebp = getPhysicalRegister(RegX8632::Reg_ebp); Variable *ebp = getPhysicalRegister(RegX8632::Reg_ebp);
Variable *esp = getPhysicalRegister(RegX8632::Reg_esp); Variable *esp = getPhysicalRegister(RegX8632::Reg_esp);
const bool SuppressStackAdjustment = true; _push(ebp);
_push(ebp, SuppressStackAdjustment);
_mov(ebp, esp); _mov(ebp, esp);
} }
......
...@@ -383,8 +383,8 @@ protected: ...@@ -383,8 +383,8 @@ protected:
void _psub(Variable *Dest, Operand *Src0) { void _psub(Variable *Dest, Operand *Src0) {
Context.insert(InstX8632Psub::create(Func, Dest, Src0)); Context.insert(InstX8632Psub::create(Func, Dest, Src0));
} }
void _push(Operand *Src0, bool SuppressStackAdjustment = false) { void _push(Variable *Src0) {
Context.insert(InstX8632Push::create(Func, Src0, SuppressStackAdjustment)); Context.insert(InstX8632Push::create(Func, Src0));
} }
void _pxor(Variable *Dest, Operand *Src0) { void _pxor(Variable *Dest, Operand *Src0) {
Context.insert(InstX8632Pxor::create(Func, Dest, Src0)); Context.insert(InstX8632Pxor::create(Func, Dest, Src0));
......
...@@ -99,18 +99,6 @@ void AssemblerX86::pushl(GPRRegister reg) { ...@@ -99,18 +99,6 @@ void AssemblerX86::pushl(GPRRegister reg) {
EmitUint8(0x50 + reg); EmitUint8(0x50 + reg);
} }
void AssemblerX86::pushl(const Address &address) {
AssemblerBuffer::EnsureCapacity ensured(&buffer_);
EmitUint8(0xFF);
EmitOperand(6, address);
}
void AssemblerX86::pushl(const Immediate &imm) {
AssemblerBuffer::EnsureCapacity ensured(&buffer_);
EmitUint8(0x68);
EmitImmediate(BrokenType, imm);
}
void AssemblerX86::popl(GPRRegister reg) { void AssemblerX86::popl(GPRRegister reg) {
AssemblerBuffer::EnsureCapacity ensured(&buffer_); AssemblerBuffer::EnsureCapacity ensured(&buffer_);
EmitUint8(0x58 + reg); EmitUint8(0x58 + reg);
......
...@@ -408,8 +408,6 @@ public: ...@@ -408,8 +408,6 @@ public:
static const intptr_t kCallExternalLabelSize = 5; static const intptr_t kCallExternalLabelSize = 5;
void pushl(GPRRegister reg); void pushl(GPRRegister reg);
void pushl(const Address &address);
void pushl(const Immediate &imm);
void popl(GPRRegister reg); void popl(GPRRegister reg);
void popl(const Address &address); void popl(const Address &address);
......
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