Commit 8555e864 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Prevent JIT cache misses from nondeterministic typecast

We were casting a 2-bit bitfield to a char using a union, which
gave us a nondeterministic result.  This works fine since we
don't care about those other bits, but it causes cache misses.
parent 691b8d69
......@@ -675,17 +675,10 @@ CompilerVariable* UnknownType::callattr(IREmitter& emitter, const OpInfo& info,
else
func = g.funcs.callattrN;
union {
CallattrFlags flags;
char value;
} flags_to_int;
static_assert(sizeof(CallattrFlags) == sizeof(char), "");
flags_to_int.flags = flags;
std::vector<llvm::Value*> other_args;
other_args.push_back(var->getValue());
other_args.push_back(embedRelocatablePtr(attr, g.llvm_str_type_ptr));
other_args.push_back(getConstantInt(flags_to_int.value, g.i8));
other_args.push_back(getConstantInt(flags.asInt(), g.i8));
llvm::Value* llvm_argspec = llvm::ConstantInt::get(g.i32, argspec.asInt(), false);
other_args.push_back(llvm_argspec);
......
......@@ -282,10 +282,12 @@ public:
M->print(sstr, 0);
sstr.flush();
llvm::sys::fs::create_directories(cache_dir.str());
std::string filename = cache_dir.str().str() + "/" + module_identifier + "_first.ll";
if (llvm::sys::fs::exists(filename))
filename = cache_dir.str().str() + "/" + module_identifier + "_second.ll";
FILE* f = fopen(filename.c_str(), "wt");
ASSERT(f, "%s", strerror(errno));
fwrite(llvm_ir.c_str(), 1, llvm_ir.size(), f);
fclose(f);
#endif
......
......@@ -586,6 +586,8 @@ struct FrameInfo {
struct CallattrFlags {
bool cls_only : 1;
bool null_on_nonexistent : 1;
char asInt() { return (cls_only << 0) + (null_on_nonexistent << 1); }
};
}
......
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