Commit b1b07129 authored by Marius Wachtler's avatar Marius Wachtler

rewriter: Remove RewriterVar::nvars because it has false positive issues.

and make code ready for the new JIT tier.
parent f45e5d7f
......@@ -135,10 +135,6 @@ void Location::dump() const {
RELEASE_ASSERT(0, "%d", type);
}
static bool isLargeConstant(int64_t val) {
return (val < (-1L << 31) || val >= (1L << 31) - 1);
}
Rewriter::ConstLoader::ConstLoader(Rewriter* rewriter) : rewriter(rewriter) {
}
......@@ -554,7 +550,7 @@ void RewriterVar::dump() {
}
assembler::Immediate RewriterVar::tryGetAsImmediate(bool* is_immediate) {
if (this->is_constant && !isLargeConstant(this->constant_value)) {
if (this->is_constant && !Rewriter::isLargeConstant(this->constant_value)) {
*is_immediate = true;
return assembler::Immediate(this->constant_value);
} else {
......@@ -568,7 +564,7 @@ assembler::Register RewriterVar::getInReg(Location dest, bool allow_constant_in_
#ifndef NDEBUG
if (!allow_constant_in_reg) {
assert(!is_constant || isLargeConstant(constant_value));
assert(!is_constant || Rewriter::isLargeConstant(constant_value));
}
#endif
......@@ -753,6 +749,18 @@ RewriterVar* Rewriter::call(bool has_side_effects, void* func_addr, RewriterVar*
return call(has_side_effects, func_addr, args, args_xmm);
}
RewriterVar* Rewriter::call(bool has_side_effects, void* func_addr, RewriterVar* arg0, RewriterVar* arg1,
RewriterVar* arg2, RewriterVar* arg3, RewriterVar* arg4) {
RewriterVar::SmallVector args;
RewriterVar::SmallVector args_xmm;
args.push_back(arg0);
args.push_back(arg1);
args.push_back(arg2);
args.push_back(arg3);
args.push_back(arg4);
return call(has_side_effects, func_addr, args, args_xmm);
}
static const Location caller_save_registers[]{
assembler::RAX, assembler::RCX, assembler::RDX, assembler::RSI, assembler::RDI,
assembler::R8, assembler::R9, assembler::R10, assembler::R11, assembler::XMM0,
......@@ -918,10 +926,14 @@ void Rewriter::_call(RewriterVar* result, bool has_side_effects, void* func_addr
if (need_to_spill) {
if (check_reg.type == Location::Register) {
spillRegister(check_reg.asRegister());
if (failed)
return;
} else {
assert(check_reg.type == Location::XMMRegister);
assert(var->locations.size() == 1);
spillRegister(check_reg.asXMMRegister());
if (failed)
return;
}
} else {
removeLocationFromVar(var, check_reg);
......@@ -1358,7 +1370,8 @@ int Rewriter::_allocate(RewriterVar* result, int n) {
consec = 0;
}
}
RELEASE_ASSERT(0, "Using all %d bytes of scratch!", scratch_size);
failed = true;
return 0;
}
RewriterVar* Rewriter::allocateAndCopy(RewriterVar* array_ptr, int n) {
......@@ -1675,9 +1688,6 @@ Rewriter::Rewriter(ICSlotRewrite* rewrite, int num_args, const std::vector<int>&
done_guarding(false) {
initPhaseCollecting();
#ifndef NDEBUG
start_vars = RewriterVar::nvars;
#endif
finished = false;
for (int i = 0; i < num_args; i++) {
......@@ -1823,10 +1833,6 @@ Rewriter* Rewriter::createRewriter(void* rtn_addr, int num_args, const char* deb
return new Rewriter(ic->startRewrite(debug_name), num_args, ic->getLiveOuts());
}
#ifndef NDEBUG
int RewriterVar::nvars = 0;
#endif
static const int INITIAL_CALL_SIZE = 13;
static const int DWARF_RBP_REGNUM = 6;
bool spillFrameArgumentIfNecessary(StackMap::Record::Location& l, uint8_t*& inst_addr, uint8_t* inst_end,
......
......@@ -266,22 +266,12 @@ private:
RewriterVar& operator=(const RewriterVar&) = delete;
public:
#ifndef NDEBUG
static int nvars;
#endif
RewriterVar(Rewriter* rewriter) : rewriter(rewriter), next_use(0), is_arg(false), is_constant(false) {
#ifndef NDEBUG
nvars++;
#endif
assert(rewriter);
}
#ifndef NDEBUG
~RewriterVar() { nvars--; }
#endif
friend class Rewriter;
friend class JitFragmentWriter;
};
class RewriterAction {
......@@ -297,7 +287,7 @@ enum class ActionType { NORMAL, GUARD, MUTATION };
#define LOCATION_PLACEHOLDER ((RewriterVar*)1)
class Rewriter : public ICSlotRewrite::CommitHook {
private:
protected:
// Helps generating the best code for loading a const integer value.
// By keeping track of the last known value of every register and reusing it.
class ConstLoader {
......@@ -335,7 +325,6 @@ private:
bool failed; // if we tried to generate an invalid rewrite.
bool finished; // committed or aborted
#ifndef NDEBUG
int start_vars;
bool phase_emitting;
void initPhaseCollecting() { phase_emitting = false; }
......@@ -477,11 +466,6 @@ public:
for (RewriterVar* var : vars) {
delete var;
}
// This check isn't thread safe and should be fine to remove if it causes
// issues (along with the nvars/start_vars accounting)
ASSERT(threading::threadWasStarted() || RewriterVar::nvars == start_vars, "%d %d", RewriterVar::nvars,
start_vars);
}
Location getReturnDestination();
......@@ -507,6 +491,8 @@ public:
RewriterVar* call(bool has_side_effects, void* func_addr, RewriterVar* arg0, RewriterVar* arg1, RewriterVar* arg2);
RewriterVar* call(bool has_side_effects, void* func_addr, RewriterVar* arg0, RewriterVar* arg1, RewriterVar* arg2,
RewriterVar* arg3);
RewriterVar* call(bool has_side_effects, void* func_addr, RewriterVar* arg0, RewriterVar* arg1, RewriterVar* arg2,
RewriterVar* arg3, RewriterVar* arg4);
RewriterVar* add(RewriterVar* a, int64_t b, Location dest);
// Allocates n pointer-sized stack slots:
RewriterVar* allocate(int n);
......@@ -521,6 +507,8 @@ public:
static Rewriter* createRewriter(void* rtn_addr, int num_args, const char* debug_name);
static bool isLargeConstant(int64_t val) { return (val < (-1L << 31) || val >= (1L << 31) - 1); }
friend class RewriterVar;
};
......
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