Commit 719cbb6d authored by Marius Wachtler's avatar Marius Wachtler

rewriter: factor out call setup code, fix scratch validation test + add assembler::skipBytes()

parent fc8b1d26
...@@ -1034,6 +1034,16 @@ void Assembler::emitAnnotation(int num) { ...@@ -1034,6 +1034,16 @@ void Assembler::emitAnnotation(int num) {
nop(); nop();
} }
void Assembler::skipBytes(int num) {
if (addr + num >= end_addr) {
addr = end_addr;
failed = true;
return;
}
addr += num;
}
ForwardJump::ForwardJump(Assembler& assembler, ConditionCode condition) ForwardJump::ForwardJump(Assembler& assembler, ConditionCode condition)
: assembler(assembler), condition(condition), jmp_inst(assembler.curInstPointer()) { : assembler(assembler), condition(condition), jmp_inst(assembler.curInstPointer()) {
assembler.jmp_cond(JumpDestination::fromStart(assembler.bytesWritten() + max_jump_size), condition); assembler.jmp_cond(JumpDestination::fromStart(assembler.bytesWritten() + max_jump_size), condition);
......
...@@ -193,6 +193,7 @@ public: ...@@ -193,6 +193,7 @@ public:
void fillWithNops(); void fillWithNops();
void fillWithNopsExcept(int bytes); void fillWithNopsExcept(int bytes);
void emitAnnotation(int num); void emitAnnotation(int num);
void skipBytes(int num);
uint8_t* startAddr() const { return start_addr; } uint8_t* startAddr() const { return start_addr; }
int bytesLeft() const { return end_addr - addr; } int bytesLeft() const { return end_addr - addr; }
......
...@@ -792,10 +792,8 @@ RewriterVar* Rewriter::call(bool has_side_effects, void* func_addr, const Rewrit ...@@ -792,10 +792,8 @@ RewriterVar* Rewriter::call(bool has_side_effects, void* func_addr, const Rewrit
return result; return result;
} }
void Rewriter::_call(RewriterVar* result, bool has_side_effects, void* func_addr, const RewriterVar::SmallVector& args, void Rewriter::_setupCall(RewriterVar* result, bool has_side_effects, const RewriterVar::SmallVector& args,
const RewriterVar::SmallVector& args_xmm) { const RewriterVar::SmallVector& args_xmm) {
assembler->comment("_call");
if (has_side_effects) if (has_side_effects)
assert(done_guarding); assert(done_guarding);
...@@ -828,9 +826,6 @@ void Rewriter::_call(RewriterVar* result, bool has_side_effects, void* func_addr ...@@ -828,9 +826,6 @@ void Rewriter::_call(RewriterVar* result, bool has_side_effects, void* func_addr
} }
} }
// RewriterVarUsage scratch = createNewVar(Location::any());
assembler::Register r = allocReg(assembler::R11);
for (int i = 0; i < args.size(); i++) { for (int i = 0; i < args.size(); i++) {
Location l(Location::forArg(i)); Location l(Location::forArg(i));
RewriterVar* var = args[i]; RewriterVar* var = args[i];
...@@ -950,6 +945,19 @@ void Rewriter::_call(RewriterVar* result, bool has_side_effects, void* func_addr ...@@ -950,6 +945,19 @@ void Rewriter::_call(RewriterVar* result, bool has_side_effects, void* func_addr
assert(!l.isClobberedByCall()); assert(!l.isClobberedByCall());
} }
#endif #endif
}
void Rewriter::_call(RewriterVar* result, bool has_side_effects, void* func_addr, const RewriterVar::SmallVector& args,
const RewriterVar::SmallVector& args_xmm) {
assembler->comment("_call");
// RewriterVarUsage scratch = createNewVar(Location::any());
assembler::Register r = allocReg(assembler::R11);
_setupCall(result, has_side_effects, args, args_xmm);
// make sure setupCall doesn't use R11
assert(vars_by_location.count(assembler::R11) == 0);
uint64_t asm_address = (uint64_t)assembler->curInstPointer() + 5; uint64_t asm_address = (uint64_t)assembler->curInstPointer() + 5;
uint64_t real_asm_address = asm_address + (uint64_t)rewrite->getSlotStart() - (uint64_t)assembler->startAddr(); uint64_t real_asm_address = asm_address + (uint64_t)rewrite->getSlotStart() - (uint64_t)assembler->startAddr();
...@@ -1737,10 +1745,10 @@ Rewriter::Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const s ...@@ -1737,10 +1745,10 @@ Rewriter::Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const s
// the entire scratch space. // the entire scratch space.
bool VALIDATE_SCRATCH_SPACE = false; bool VALIDATE_SCRATCH_SPACE = false;
if (VALIDATE_SCRATCH_SPACE) { if (VALIDATE_SCRATCH_SPACE) {
int scratch_size = rewrite->getScratchSize(); int scratch_size = this->rewrite->getScratchSize();
for (int i = 0; i < scratch_size; i += 8) { for (int i = 0; i < scratch_size; i += 8) {
assembler->movq(assembler::Immediate(0x12345678UL), assembler->movq(assembler::Immediate(0x12345678UL),
assembler::Indirect(assembler::RSP, i + rewrite->getScratchRspOffset())); assembler::Indirect(assembler::RSP, i + this->rewrite->getScratchRspOffset()));
} }
} }
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <memory> #include <memory>
#include <tuple> #include <tuple>
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallSet.h"
...@@ -349,7 +350,7 @@ protected: ...@@ -349,7 +350,7 @@ protected:
Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const std::vector<int>& live_outs); Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const std::vector<int>& live_outs);
llvm::SmallVector<RewriterAction, 32> actions; llvm::SmallVector<RewriterAction, 32> actions;
void addAction(std::function<void()> action, std::vector<RewriterVar*> const& vars, ActionType type) { void addAction(std::function<void()> action, llvm::ArrayRef<RewriterVar*> vars, ActionType type) {
assertPhaseCollecting(); assertPhaseCollecting();
for (RewriterVar* var : vars) { for (RewriterVar* var : vars) {
assert(var != NULL); assert(var != NULL);
...@@ -413,6 +414,8 @@ protected: ...@@ -413,6 +414,8 @@ protected:
void _trap(); void _trap();
void _loadConst(RewriterVar* result, int64_t val); void _loadConst(RewriterVar* result, int64_t val);
void _setupCall(RewriterVar* result, bool has_side_effects, const RewriterVar::SmallVector& args,
const RewriterVar::SmallVector& args_xmm);
void _call(RewriterVar* result, bool has_side_effects, void* func_addr, const RewriterVar::SmallVector& args, void _call(RewriterVar* result, bool has_side_effects, void* func_addr, const RewriterVar::SmallVector& args,
const RewriterVar::SmallVector& args_xmm); const RewriterVar::SmallVector& args_xmm);
void _add(RewriterVar* result, RewriterVar* a, int64_t b, Location dest); void _add(RewriterVar* result, RewriterVar* a, int64_t b, Location dest);
......
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