From 855534b152e3f25e4549a249f2d889b569e53bff Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 19:07:10 -0600 Subject: [PATCH 01/89] introduce ir::Type and begin migrating i2f and friends to it --- include/avian/codegen/compiler.h | 7 ++- include/avian/codegen/ir.h | 105 +++++++++++++++++++++++++++++++ src/codegen/compiler.cpp | 39 ++++++++---- src/compile.cpp | 22 ++++--- 4 files changed, 148 insertions(+), 25 deletions(-) create mode 100644 include/avian/codegen/ir.h diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index f31d5fc320..f2962b9718 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -14,6 +14,7 @@ #include #include "avian/zone.h" #include "assembler.h" +#include "ir.h" namespace avian { namespace codegen { @@ -134,9 +135,9 @@ class Compiler { virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) = 0; virtual void nullaryOp(lir::Operation type) = 0; - virtual Operand* f2f(unsigned aSize, unsigned resSize, Operand* a) = 0; - virtual Operand* f2i(unsigned aSize, unsigned resSize, Operand* a) = 0; - virtual Operand* i2f(unsigned aSize, unsigned resSize, Operand* a) = 0; + virtual Operand* f2f(unsigned aSize, ir::Type resType, Operand* a) = 0; + virtual Operand* f2i(unsigned aSize, ir::Type resType, Operand* a) = 0; + virtual Operand* i2f(unsigned aSize, ir::Type resType, Operand* a) = 0; virtual void compile(uintptr_t stackOverflowHandler, unsigned stackLimitOffset) = 0; diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h new file mode 100644 index 0000000000..e3c6f0ed13 --- /dev/null +++ b/include/avian/codegen/ir.h @@ -0,0 +1,105 @@ +/* Copyright (c) 2008-2014, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#ifndef AVIAN_CODEGEN_IR_H +#define AVIAN_CODEGEN_IR_H + +namespace avian { +namespace codegen { +namespace ir { + +class Type { + public: + enum Flavor { + // A GC-visiible reference + Object, + + // GC-invisible types + Integer, + Float + }; + + private: + uint8_t flavor_; + uint8_t size_; + + friend class Types; + + public: + Type(uint8_t flavor_, uint8_t size_) : flavor_(flavor_), size_(size_) + { + } + + inline Flavor flavor() const + { + return (Flavor)flavor_; + } + + inline unsigned size() const + { + return size_; + } + + inline bool operator==(const Type& other) const + { + return flavor_ == other.flavor_ && size_ == other.size_; + } + + inline bool operator!=(const Type& other) const + { + return !(*this == other); + } +}; + +class Types { + public: + // An object reference type, which will be treated as a GC root + Type object; + + // A pointer-sized integer type (neither/both signed or unsigned) + // Note that these are just integers from the GC's perspective. + Type address; + + // A 1-byte integer type (neither/both signed or unsigned) + Type i1; + + // A 2-byte integer type (neither/both signed or unsigned) + Type i2; + + // A 4-byte integer type (neither/both signed or unsigned) + Type i4; + + // A 8-byte integer type (neither/both signed or unsigned) + Type i8; + + // A 4-byte floating point type + Type f4; + + // A 8-byte floating point type + Type f8; + + Types(unsigned bytesPerWord) + : object(Type::Object, bytesPerWord), + address(Type::Integer, bytesPerWord), + i1(Type::Integer, 1), + i2(Type::Integer, 2), + i4(Type::Integer, 4), + i8(Type::Integer, 8), + f4(Type::Float, 4), + f8(Type::Float, 8) + { + } +}; + +} // namespace ir +} // namespace codegen +} // namespace avian + +#endif // AVIAN_CODEGEN_IR_H diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index d987912257..cadcb3dc21 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2630,28 +2630,43 @@ class MyCompiler: public Compiler { appendTranslate(&c, type, size, static_cast(a), size, result); return result; } - - virtual Operand* f2f(unsigned aSize, unsigned resSize, Operand* a) { + + virtual Operand* f2f(unsigned aSize, ir::Type resType, Operand* a) + { assert(&c, static_cast(a)->type == lir::ValueFloat); Value* result = value(&c, lir::ValueFloat); - appendTranslate - (&c, lir::Float2Float, aSize, static_cast(a), resSize, result); + appendTranslate(&c, + lir::Float2Float, + aSize, + static_cast(a), + resType.size(), + result); return result; } - - virtual Operand* f2i(unsigned aSize, unsigned resSize, Operand* a) { + + virtual Operand* f2i(unsigned aSize, ir::Type resType, Operand* a) + { assert(&c, static_cast(a)->type == lir::ValueFloat); Value* result = value(&c, lir::ValueGeneral); - appendTranslate - (&c, lir::Float2Int, aSize, static_cast(a), resSize, result); + appendTranslate(&c, + lir::Float2Int, + aSize, + static_cast(a), + resType.size(), + result); return result; } - - virtual Operand* i2f(unsigned aSize, unsigned resSize, Operand* a) { + + virtual Operand* i2f(unsigned aSize, ir::Type resType, Operand* a) + { assert(&c, static_cast(a)->type == lir::ValueGeneral); Value* result = value(&c, lir::ValueFloat); - appendTranslate - (&c, lir::Int2Float, aSize, static_cast(a), resSize, result); + appendTranslate(&c, + lir::Int2Float, + aSize, + static_cast(a), + resType.size(), + result); return result; } diff --git a/src/compile.cpp b/src/compile.cpp index cd13d8f59a..752754d982 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4020,6 +4020,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, unsigned newIp; stack.pushValue(Return); + ir::Types types(TargetBytesPerWord); + start: uint8_t* stackMap = static_cast(stack.push(stackSize)); frame = new (stack.push(sizeof(Frame))) Frame(frame, stackMap); @@ -4374,15 +4376,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case d2f: { - frame->pushInt(c->f2f(8, 4, frame->popLong())); + frame->pushInt(c->f2f(8, types.f4, frame->popLong())); } break; case d2i: { - frame->pushInt(c->f2i(8, 4, frame->popLong())); + frame->pushInt(c->f2i(8, types.f4, frame->popLong())); } break; case d2l: { - frame->pushLong(c->f2i(8, 8, frame->popLong())); + frame->pushLong(c->f2i(8, types.f8, frame->popLong())); } break; case dadd: @@ -4467,15 +4469,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case f2d: { - frame->pushLong(c->f2f(4, 8, frame->popInt())); + frame->pushLong(c->f2f(4, types.f8, frame->popInt())); } break; case f2i: { - frame->pushInt(c->f2i(4, 4, frame->popInt())); + frame->pushInt(c->f2i(4, types.f4, frame->popInt())); } break; case f2l: { - frame->pushLong(c->f2i(4, 8, frame->popInt())); + frame->pushLong(c->f2i(4, types.f8, frame->popInt())); } break; case fadd: @@ -4751,11 +4753,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2d: { - frame->pushLong(c->i2f(4, 8, frame->popInt())); + frame->pushLong(c->i2f(4, types.f8, frame->popInt())); } break; case i2f: { - frame->pushInt(c->i2f(4, 4, frame->popInt())); + frame->pushInt(c->i2f(4, types.f4, frame->popInt())); } break; case i2l: @@ -5235,11 +5237,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto start; case l2d: { - frame->pushLong(c->i2f(8, 8, frame->popLong())); + frame->pushLong(c->i2f(8, types.f8, frame->popLong())); } break; case l2f: { - frame->pushInt(c->i2f(8, 4, frame->popLong())); + frame->pushInt(c->i2f(8, types.f4, frame->popLong())); } break; case l2i: From 587b1e3eda57bbb07af4958b17822516e96fa3df Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 19:50:32 -0600 Subject: [PATCH 02/89] use ir::Type in place of lir::ValueType in Value --- src/codegen/compiler.cpp | 24 +++++++++++++----------- src/codegen/compiler/regalloc.cpp | 4 ++-- src/codegen/compiler/value.cpp | 24 +++++++++++++++++++++--- src/codegen/compiler/value.h | 15 +++++++++------ src/compile.cpp | 8 ++++---- 5 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index cadcb3dc21..97e39581b4 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -821,7 +821,7 @@ maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, c->arch->planSource(type, dstSize, src, dstSize, &thunk); - if (srcValue->type == lir::ValueGeneral) { + if (isGeneralValue(srcValue)) { src.registerMask &= c->regFile->generalRegisters.mask; } @@ -1506,8 +1506,8 @@ resolveOriginalSites(Context* c, Event* e, SiteRecordList* frozen, fprintf(stderr, "freeze original %s for %p local %d frame %d\n", buffer, v, el.localIndex, el.frameIndex(c)); } - - Value dummy(0, 0, lir::ValueGeneral); + + Value dummy(0, 0, ir::Type(ir::Type::Integer, TargetBytesPerWord)); dummy.addSite(c, s); dummy.removeSite(c, s); freeze(c, frozen, s, 0); @@ -2536,8 +2536,7 @@ class MyCompiler: public Compiler { for (int i = 0; i < static_cast(c.localFootprint); ++i) { Local* local = e->locals() + i; if (local->value) { - initLocal - (1, i, local->value->type == lir::ValueGeneral ? IntegerType : FloatType); + initLocal(1, i, isGeneralValue(local->value) ? IntegerType : FloatType); } } @@ -2633,8 +2632,9 @@ class MyCompiler: public Compiler { virtual Operand* f2f(unsigned aSize, ir::Type resType, Operand* a) { - assert(&c, static_cast(a)->type == lir::ValueFloat); - Value* result = value(&c, lir::ValueFloat); + assert(&c, isFloatValue(a)); + assert(&c, resType.flavor() == ir::Type::Float); + Value* result = value(&c, resType); appendTranslate(&c, lir::Float2Float, aSize, @@ -2646,8 +2646,9 @@ class MyCompiler: public Compiler { virtual Operand* f2i(unsigned aSize, ir::Type resType, Operand* a) { - assert(&c, static_cast(a)->type == lir::ValueFloat); - Value* result = value(&c, lir::ValueGeneral); + assert(&c, isFloatValue(a)); + assert(&c, resType.flavor() != ir::Type::Float); + Value* result = value(&c, resType); appendTranslate(&c, lir::Float2Int, aSize, @@ -2659,8 +2660,9 @@ class MyCompiler: public Compiler { virtual Operand* i2f(unsigned aSize, ir::Type resType, Operand* a) { - assert(&c, static_cast(a)->type == lir::ValueGeneral); - Value* result = value(&c, lir::ValueFloat); + assert(&c, isGeneralValue(a)); + assert(&c, resType.flavor() == ir::Type::Float); + Value* result = value(&c, resType); appendTranslate(&c, lir::Int2Float, aSize, diff --git a/src/codegen/compiler/regalloc.cpp b/src/codegen/compiler/regalloc.cpp index ba7c6711ab..8699838900 100644 --- a/src/codegen/compiler/regalloc.cpp +++ b/src/codegen/compiler/regalloc.cpp @@ -215,12 +215,12 @@ pickTarget(Context* c, Read* read, bool intersectRead, Value* value = read->value; uint32_t registerMask - = (value->type == lir::ValueFloat ? ~0 : c->regFile->generalRegisters.mask); + = (isFloatValue(value) ? ~0 : c->regFile->generalRegisters.mask); SiteMask mask(~0, registerMask, AnyFrameIndex); read->intersect(&mask); - if (value->type == lir::ValueFloat) { + if (isFloatValue(value)) { uint32_t floatMask = mask.registerMask & c->regFile->floatRegisters.mask; if (floatMask) { mask.registerMask = floatMask; diff --git a/src/codegen/compiler/value.cpp b/src/codegen/compiler/value.cpp index eccb2b9cb1..12a9ef6b5c 100644 --- a/src/codegen/compiler/value.cpp +++ b/src/codegen/compiler/value.cpp @@ -17,9 +17,17 @@ namespace avian { namespace codegen { namespace compiler { -Value::Value(Site* site, Site* target, lir::ValueType type): - reads(0), lastRead(0), sites(site), source(0), target(target), buddy(this), - nextWord(this), home(NoFrameIndex), type(type), wordIndex(0) +Value::Value(Site* site, Site* target, ir::Type type) + : reads(0), + lastRead(0), + sites(site), + source(0), + target(target), + buddy(this), + nextWord(this), + home(NoFrameIndex), + wordIndex(0), + type(type) { } bool Value::findSite(Site* site) { @@ -156,6 +164,16 @@ bool Value::hasBuddy(Context* c, Value* b) { Value* value(Context* c, lir::ValueType type, Site* site, Site* target) { + return value( + c, + ir::Type(type == lir::ValueGeneral ? ir::Type::Integer : ir::Type::Float, + vm::TargetBytesPerWord), + site, + target); +} + +Value* value(Context* c, ir::Type type, Site* site, Site* target) +{ return new(c->zone) Value(site, target, type); } diff --git a/src/codegen/compiler/value.h b/src/codegen/compiler/value.h index a9723782ea..8db231639e 100644 --- a/src/codegen/compiler/value.h +++ b/src/codegen/compiler/value.h @@ -36,10 +36,10 @@ class Value: public Compiler::Operand { Value* buddy; Value* nextWord; int16_t home; - lir::ValueType type; uint8_t wordIndex; + ir::Type type; - Value(Site* site, Site* target, lir::ValueType type); + Value(Site* site, Site* target, ir::Type type); bool findSite(Site* site); @@ -67,15 +67,18 @@ class Value: public Compiler::Operand { }; -inline bool isGeneralValue(Compiler::Operand* a) { - return static_cast(a)->type == lir::ValueGeneral; +inline bool isFloatValue(Compiler::Operand* a) +{ + return static_cast(a)->type.flavor() == ir::Type::Float; } -inline bool isFloatValue(Compiler::Operand* a) { - return static_cast(a)->type == lir::ValueFloat; +inline bool isGeneralValue(Compiler::Operand* a) +{ + return !isFloatValue(a); } Value* value(Context* c, lir::ValueType type, Site* site = 0, Site* target = 0); +Value* value(Context* c, ir::Type type, Site* site = 0, Site* target = 0); } // namespace compiler } // namespace codegen diff --git a/src/compile.cpp b/src/compile.cpp index 752754d982..e1aa54d4eb 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4380,11 +4380,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case d2i: { - frame->pushInt(c->f2i(8, types.f4, frame->popLong())); + frame->pushInt(c->f2i(8, types.i4, frame->popLong())); } break; case d2l: { - frame->pushLong(c->f2i(8, types.f8, frame->popLong())); + frame->pushLong(c->f2i(8, types.i8, frame->popLong())); } break; case dadd: @@ -4473,11 +4473,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case f2i: { - frame->pushInt(c->f2i(4, types.f4, frame->popInt())); + frame->pushInt(c->f2i(4, types.i4, frame->popInt())); } break; case f2l: { - frame->pushLong(c->f2i(4, types.f8, frame->popInt())); + frame->pushLong(c->f2i(4, types.i8, frame->popInt())); } break; case fadd: From d9fee1025c657864029ab6dd8a17ebde17b4a7ab Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 20:01:14 -0600 Subject: [PATCH 03/89] use ir::Type in Compiler::return_ --- include/avian/codegen/compiler.h | 3 ++- src/codegen/compiler.cpp | 15 ++++++++++++--- src/compile.cpp | 22 ++++++++++++++++------ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index f2962b9718..c9692be59d 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -106,7 +106,8 @@ class Compiler { OperandType resultType, unsigned argumentFootprint) = 0; - virtual void return_(unsigned size, Operand* value) = 0; + virtual void return_(ir::Type type, Operand* value) = 0; + virtual void return_() = 0; virtual void initLocal(unsigned size, unsigned index, OperandType type) = 0; virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 97e39581b4..4e5cf2462d 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2478,8 +2478,17 @@ class MyCompiler: public Compiler { return result; } - virtual void return_(unsigned size, Operand* value) { - appendReturn(&c, size, static_cast(value)); + virtual void return_(ir::Type type, Operand* value) + { + // TODO: once type information is flowed properly, enable this assert. + // Some time later, we can remove the parameter. + // assert(&c, static_cast(value)->type == type); + appendReturn(&c, type.size(), static_cast(value)); + } + + virtual void return_() + { + appendReturn(&c, 0, 0); } virtual void initLocal(unsigned footprint, unsigned index, OperandType type) @@ -2498,7 +2507,7 @@ class MyCompiler: public Compiler { lowIndex = index; } else { lowIndex = index + 1; - highIndex = index; + highIndex = index; } if (TargetBytesPerWord == 4) { diff --git a/src/compile.cpp b/src/compile.cpp index e1aa54d4eb..3a74746262 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4290,7 +4290,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case areturn: { handleExit(t, frame); - c->return_(TargetBytesPerWord, frame->popObject()); + c->return_(types.address, frame->popObject()); } goto next; case arraylength: { @@ -5179,10 +5179,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->binaryOp(lir::Remainder, 4, a, b)); } break; - case ireturn: + case ireturn: { + handleExit(t, frame); + c->return_(types.i4, frame->popInt()); + } + goto next; + case freturn: { handleExit(t, frame); - c->return_(4, frame->popInt()); + c->return_(types.f4, frame->popInt()); } goto next; case istore: @@ -5472,10 +5477,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushLong(c->binaryOp(lir::Remainder, 8, a, b)); } break; - case lreturn: + case lreturn: { + handleExit(t, frame); + c->return_(types.i8, frame->popLong()); + } + goto next; + case dreturn: { handleExit(t, frame); - c->return_(8, frame->popLong()); + c->return_(types.f8, frame->popLong()); } goto next; case lshl: @@ -5887,7 +5897,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } handleExit(t, frame); - c->return_(0, 0); + c->return_(); goto next; case sipush: From 49a5a9f39871374b59fdf1525de4fa95711492c1 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 20:11:54 -0600 Subject: [PATCH 04/89] use ir::Type in Compiler::push --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 22 +++++- src/compile.cpp | 112 ++++++++++++++++--------------- 3 files changed, 79 insertions(+), 57 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index c9692be59d..0c70db57e1 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -83,7 +83,7 @@ class Compiler { virtual Operand* register_(int number) = 0; virtual void push(unsigned footprint) = 0; - virtual void push(unsigned footprint, Operand* value) = 0; + virtual void push(ir::Type type, Operand* value) = 0; virtual void save(unsigned footprint, Operand* value) = 0; virtual Operand* pop(unsigned footprint) = 0; virtual void pushed() = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 4e5cf2462d..5083b8acc6 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2110,6 +2110,20 @@ class Client: public Assembler::Client { Context* c; }; +unsigned typeFootprint(Context* c, ir::Type type) +{ + // TODO: this function is very Java-specific in nature. Generalize. + switch (type.flavor()) { + case ir::Type::Float: + case ir::Type::Integer: + return type.size() / 4; + case ir::Type::Object: + return 1; + default: + abort(c); + } +} + class MyCompiler: public Compiler { public: MyCompiler(System* s, Assembler* assembler, Zone* zone, @@ -2335,8 +2349,12 @@ class MyCompiler: public Compiler { c.stack = s; } - virtual void push(unsigned footprint, Operand* value) { - compiler::push(&c, footprint, static_cast(value)); + virtual void push(ir::Type type, Operand* value) + { + // TODO: once type information is flowed properly, enable this assert. + // Some time later, we can remove the parameter. + // assert(&c, static_cast(value)->type == type); + compiler::push(&c, typeFootprint(&c, type), static_cast(value)); } virtual void save(unsigned footprint, Operand* value) { diff --git a/src/compile.cpp b/src/compile.cpp index 3a74746262..500543ed5a 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1358,28 +1358,30 @@ class Frame { typedef Compiler::Operand* Value; - Frame(Context* context, uint8_t* stackMap): - context(context), - t(context->thread), - c(context->compiler), - subroutine(0), - stackMap(stackMap), - ip(0), - sp(localSize()), - level(0) + Frame(Context* context, uint8_t* stackMap) + : context(context), + t(context->thread), + c(context->compiler), + subroutine(0), + stackMap(stackMap), + ip(0), + sp(localSize()), + level(0), + types(TargetBytesPerWord) { memset(stackMap, 0, codeMaxStack(t, methodCode(t, context->method))); } - Frame(Frame* f, uint8_t* stackMap): - context(f->context), - t(context->thread), - c(context->compiler), - subroutine(f->subroutine), - stackMap(stackMap), - ip(f->ip), - sp(f->sp), - level(f->level + 1) + Frame(Frame* f, uint8_t* stackMap) + : context(f->context), + t(context->thread), + c(context->compiler), + subroutine(f->subroutine), + stackMap(stackMap), + ip(f->ip), + sp(f->sp), + level(f->level + 1), + types(TargetBytesPerWord) { memcpy(stackMap, f->stackMap, codeMaxStack (t, methodCode(t, context->method))); @@ -1677,12 +1679,13 @@ class Frame { this->ip = ip; } - void pushQuiet(unsigned footprint, Value o) { - c->push(footprint, o); + void pushQuiet(ir::Type type, Value o) + { + c->push(type, o); } void pushLongQuiet(Value o) { - pushQuiet(2, o); + pushQuiet(types.i8, o); } Value popQuiet(unsigned footprint) { @@ -1694,17 +1697,17 @@ class Frame { } void pushInt(Value o) { - pushQuiet(1, o); + pushQuiet(types.i4, o); pushedInt(); } void pushAddress(Value o) { - pushQuiet(1, o); + pushQuiet(types.i4, o); pushedInt(); } void pushObject(Value o) { - pushQuiet(1, o); + pushQuiet(types.object, o); pushedObject(); } @@ -1784,7 +1787,7 @@ class Frame { } void dup() { - pushQuiet(1, c->peek(1, 0)); + pushQuiet(types.i4, c->peek(1, 0)); dupped(); } @@ -1793,9 +1796,9 @@ class Frame { Value s0 = popQuiet(1); Value s1 = popQuiet(1); - pushQuiet(1, s0); - pushQuiet(1, s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); duppedX1(); } @@ -1806,17 +1809,17 @@ class Frame { if (get(sp - 2) == Long) { Value s1 = popLongQuiet(); - pushQuiet(1, s0); + pushQuiet(types.i4, s0); pushLongQuiet(s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s0); } else { Value s1 = popQuiet(1); Value s2 = popQuiet(1); - pushQuiet(1, s0); - pushQuiet(1, s2); - pushQuiet(1, s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s2); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); } duppedX2(); @@ -1829,10 +1832,10 @@ class Frame { Value s0 = popQuiet(1); Value s1 = popQuiet(1); - pushQuiet(1, s1); - pushQuiet(1, s0); - pushQuiet(1, s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); } dupped2(); @@ -1844,18 +1847,18 @@ class Frame { Value s1 = popQuiet(1); pushLongQuiet(s0); - pushQuiet(1, s1); + pushQuiet(types.i4, s1); pushLongQuiet(s0); } else { Value s0 = popQuiet(1); Value s1 = popQuiet(1); Value s2 = popQuiet(1); - pushQuiet(1, s1); - pushQuiet(1, s0); - pushQuiet(1, s2); - pushQuiet(1, s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s2); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); } dupped2X1(); @@ -1876,8 +1879,8 @@ class Frame { Value s2 = popQuiet(1); pushLongQuiet(s0); - pushQuiet(1, s2); - pushQuiet(1, s1); + pushQuiet(types.i4, s2); + pushQuiet(types.i4, s1); pushLongQuiet(s0); } } else { @@ -1886,12 +1889,12 @@ class Frame { Value s2 = popQuiet(1); Value s3 = popQuiet(1); - pushQuiet(1, s1); - pushQuiet(1, s0); - pushQuiet(1, s3); - pushQuiet(1, s2); - pushQuiet(1, s1); - pushQuiet(1, s0); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s3); + pushQuiet(types.i4, s2); + pushQuiet(types.i4, s1); + pushQuiet(types.i4, s0); } dupped2X2(); @@ -1901,8 +1904,8 @@ class Frame { Value s0 = popQuiet(1); Value s1 = popQuiet(1); - pushQuiet(1, s0); - pushQuiet(1, s1); + pushQuiet(types.i4, s0); + pushQuiet(types.i4, s1); swapped(); } @@ -1996,6 +1999,7 @@ class Frame { unsigned ip; unsigned sp; unsigned level; + ir::Types types; }; unsigned From 75f0812f7ab34204585c827d4ad4c1bf836313c5 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 20:16:14 -0600 Subject: [PATCH 05/89] remove unused Compiler::push method --- include/avian/codegen/compiler.h | 1 - src/codegen/compiler.cpp | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 0c70db57e1..acd1e3adc3 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -82,7 +82,6 @@ class Compiler { virtual Operand* register_(int number) = 0; - virtual void push(unsigned footprint) = 0; virtual void push(ir::Type type, Operand* value) = 0; virtual void save(unsigned footprint, Operand* value) = 0; virtual Operand* pop(unsigned footprint) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 5083b8acc6..ba55b830ea 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2339,16 +2339,6 @@ class MyCompiler: public Compiler { return c.logicalCode[c.logicalIp]->lastEvent->makeCodePromise(&c); } - virtual void push(unsigned footprint UNUSED) { - assert(&c, footprint == 1); - - Value* v = value(&c, lir::ValueGeneral); - Stack* s = compiler::stack(&c, v, c.stack); - - v->home = frameIndex(&c, s->index + c.localFootprint); - c.stack = s; - } - virtual void push(ir::Type type, Operand* value) { // TODO: once type information is flowed properly, enable this assert. From 13342d28bee46bc1317445a2d8fa0e65550339d0 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 20:20:19 -0600 Subject: [PATCH 06/89] use ir::Type in Compiler::save --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 10 ++++++++-- src/compile.cpp | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index acd1e3adc3..574015d1ff 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -83,7 +83,7 @@ class Compiler { virtual Operand* register_(int number) = 0; virtual void push(ir::Type type, Operand* value) = 0; - virtual void save(unsigned footprint, Operand* value) = 0; + virtual void save(ir::Type type, Operand* value) = 0; virtual Operand* pop(unsigned footprint) = 0; virtual void pushed() = 0; virtual void popped(unsigned footprint) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index ba55b830ea..2f694a3554 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2347,13 +2347,19 @@ class MyCompiler: public Compiler { compiler::push(&c, typeFootprint(&c, type), static_cast(value)); } - virtual void save(unsigned footprint, Operand* value) { + virtual void save(ir::Type type, Operand* value) + { + // TODO: once type information is flowed properly, enable this assert. + // Some time later, we can remove the parameter. + // assert(&c, static_cast(value)->type == type); + unsigned footprint = typeFootprint(&c, type); c.saved = cons(&c, static_cast(value), c.saved); if (TargetBytesPerWord == 4 and footprint > 1) { assert(&c, footprint == 2); assert(&c, static_cast(value)->nextWord); - save(1, static_cast(value)->nextWord); + save(ir::Type(ir::Type::Integer, 4), + static_cast(value)->nextWord); } } diff --git a/src/compile.cpp b/src/compile.cpp index 500543ed5a..c2657a555c 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -5950,7 +5950,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->condJump(lir::JumpIfLess, 4, c->constant(bottom, Compiler::IntegerType), key, frame->machineIp(defaultIp)); - c->save(1, key); + c->save(types.i4, key); new (stack.push(sizeof(SwitchState))) SwitchState (c->saveState(), count, defaultIp, key, start, bottom, top); @@ -6036,8 +6036,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->condJump(lir::JumpIfGreater, 4, c->constant(s->top, Compiler::IntegerType), s->key, frame->machineIp(s->defaultIp)); - - c->save(1, s->key); + + c->save(types.i4, s->key); ip = s->defaultIp; stack.pushValue(Untable1); } goto start; From 4bfb359cddf24e8bf31d08d624236fe1f403ac29 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 20:28:33 -0600 Subject: [PATCH 07/89] use ir::Type in Compiler::pop --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 9 ++++-- src/compile.cpp | 51 ++++++++++++++++---------------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 574015d1ff..88b87886e3 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -84,7 +84,7 @@ class Compiler { virtual void push(ir::Type type, Operand* value) = 0; virtual void save(ir::Type type, Operand* value) = 0; - virtual Operand* pop(unsigned footprint) = 0; + virtual Operand* pop(ir::Type type) = 0; virtual void pushed() = 0; virtual void popped(unsigned footprint) = 0; virtual unsigned topOfStack() = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 2f694a3554..d1052c0ff0 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2363,8 +2363,13 @@ class MyCompiler: public Compiler { } } - virtual Operand* pop(unsigned footprint) { - return compiler::pop(&c, footprint); + virtual Operand* pop(ir::Type type) + { + Operand* value = compiler::pop(&c, typeFootprint(&c, type)); + // TODO: once type information is flowed properly, enable this assert. + // Some time later, we can remove the parameter. + // assert(&c, static_cast(value)->type == type); + return value; } virtual void pushed() { diff --git a/src/compile.cpp b/src/compile.cpp index c2657a555c..b86cf25589 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1688,12 +1688,13 @@ class Frame { pushQuiet(types.i8, o); } - Value popQuiet(unsigned footprint) { - return c->pop(footprint); + Value popQuiet(ir::Type type) + { + return c->pop(type); } Value popLongQuiet() { - return popQuiet(2); + return popQuiet(types.i8); } void pushInt(Value o) { @@ -1729,7 +1730,7 @@ class Frame { Value popInt() { poppedInt(); - return popQuiet(1); + return popQuiet(types.i4); } Value popLong() { @@ -1739,7 +1740,7 @@ class Frame { Value popObject() { poppedObject(); - return popQuiet(1); + return popQuiet(types.object); } void loadInt(unsigned index) { @@ -1773,7 +1774,7 @@ class Frame { } void storeObjectOrAddress(unsigned index) { - storeLocal(context, 1, popQuiet(1), index); + storeLocal(context, 1, popQuiet(types.i4), index); assert(t, sp >= 1); assert(t, sp - 1 >= localSize()); @@ -1793,8 +1794,8 @@ class Frame { } void dupX1() { - Value s0 = popQuiet(1); - Value s1 = popQuiet(1); + Value s0 = popQuiet(types.i4); + Value s1 = popQuiet(types.i4); pushQuiet(types.i4, s0); pushQuiet(types.i4, s1); @@ -1804,7 +1805,7 @@ class Frame { } void dupX2() { - Value s0 = popQuiet(1); + Value s0 = popQuiet(types.i4); if (get(sp - 2) == Long) { Value s1 = popLongQuiet(); @@ -1813,8 +1814,8 @@ class Frame { pushLongQuiet(s1); pushQuiet(types.i4, s0); } else { - Value s1 = popQuiet(1); - Value s2 = popQuiet(1); + Value s1 = popQuiet(types.i4); + Value s2 = popQuiet(types.i4); pushQuiet(types.i4, s0); pushQuiet(types.i4, s2); @@ -1829,8 +1830,8 @@ class Frame { if (get(sp - 1) == Long) { pushLongQuiet(c->peek(2, 0)); } else { - Value s0 = popQuiet(1); - Value s1 = popQuiet(1); + Value s0 = popQuiet(types.i4); + Value s1 = popQuiet(types.i4); pushQuiet(types.i4, s1); pushQuiet(types.i4, s0); @@ -1844,15 +1845,15 @@ class Frame { void dup2X1() { if (get(sp - 1) == Long) { Value s0 = popLongQuiet(); - Value s1 = popQuiet(1); + Value s1 = popQuiet(types.i4); pushLongQuiet(s0); pushQuiet(types.i4, s1); pushLongQuiet(s0); } else { - Value s0 = popQuiet(1); - Value s1 = popQuiet(1); - Value s2 = popQuiet(1); + Value s0 = popQuiet(types.i4); + Value s1 = popQuiet(types.i4); + Value s2 = popQuiet(types.i4); pushQuiet(types.i4, s1); pushQuiet(types.i4, s0); @@ -1875,8 +1876,8 @@ class Frame { pushLongQuiet(s1); pushLongQuiet(s0); } else { - Value s1 = popQuiet(1); - Value s2 = popQuiet(1); + Value s1 = popQuiet(types.i4); + Value s2 = popQuiet(types.i4); pushLongQuiet(s0); pushQuiet(types.i4, s2); @@ -1884,10 +1885,10 @@ class Frame { pushLongQuiet(s0); } } else { - Value s0 = popQuiet(1); - Value s1 = popQuiet(1); - Value s2 = popQuiet(1); - Value s3 = popQuiet(1); + Value s0 = popQuiet(types.i4); + Value s1 = popQuiet(types.i4); + Value s2 = popQuiet(types.i4); + Value s3 = popQuiet(types.i4); pushQuiet(types.i4, s1); pushQuiet(types.i4, s0); @@ -1901,8 +1902,8 @@ class Frame { } void swap() { - Value s0 = popQuiet(1); - Value s1 = popQuiet(1); + Value s0 = popQuiet(types.i4); + Value s1 = popQuiet(types.i4); pushQuiet(types.i4, s0); pushQuiet(types.i4, s1); From d8914a9646bf44f587257733c30ee70a6f39b449 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 21:35:08 -0600 Subject: [PATCH 08/89] use ir::Type in Compiler::initLocal --- include/avian/codegen/compiler.h | 2 +- include/avian/codegen/ir.h | 8 +++++++- src/codegen/compiler.cpp | 12 ++++++++---- src/compile.cpp | 18 +++++++++--------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 88b87886e3..e43edb75b1 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -108,7 +108,7 @@ class Compiler { virtual void return_(ir::Type type, Operand* value) = 0; virtual void return_() = 0; - virtual void initLocal(unsigned size, unsigned index, OperandType type) = 0; + virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0; virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0; virtual void storeLocal(unsigned footprint, Operand* src, unsigned index) = 0; diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h index e3c6f0ed13..8ed577b91c 100644 --- a/include/avian/codegen/ir.h +++ b/include/avian/codegen/ir.h @@ -23,7 +23,13 @@ class Type { // GC-invisible types Integer, - Float + Float, + Address, + + // Represents individual halves of two-word types + // (double/long on 32-bit systems) + // TODO: remove when possible + Half, }; private: diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index d1052c0ff0..af0ce8abdc 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2118,6 +2118,8 @@ unsigned typeFootprint(Context* c, ir::Type type) case ir::Type::Integer: return type.size() / 4; case ir::Type::Object: + case ir::Type::Address: + case ir::Type::Half: return 1; default: abort(c); @@ -2274,7 +2276,7 @@ class MyCompiler: public Compiler { for (unsigned li = 0; li < c.localFootprint; ++li) { Local* local = c.locals + li; if (local->value == 0) { - initLocal(1, li, IntegerType); + initLocal(1, li, ir::Type(ir::Type::Address, TargetBytesPerWord)); } } } @@ -2510,11 +2512,13 @@ class MyCompiler: public Compiler { appendReturn(&c, 0, 0); } - virtual void initLocal(unsigned footprint, unsigned index, OperandType type) + virtual void initLocal(unsigned footprint, unsigned index, ir::Type type) { + // TODO: enable the following assertion when possible: + // assert(&c, footprint == typeFootprint(type)); assert(&c, index + footprint <= c.localFootprint); - Value* v = value(&c, valueType(&c, type)); + Value* v = value(&c, type); if (footprint > 1) { assert(&c, footprint == 2); @@ -2564,7 +2568,7 @@ class MyCompiler: public Compiler { for (int i = 0; i < static_cast(c.localFootprint); ++i) { Local* local = e->locals() + i; if (local->value) { - initLocal(1, i, isGeneralValue(local->value) ? IntegerType : FloatType); + initLocal(1, i, local->value->type); } } diff --git a/src/compile.cpp b/src/compile.cpp index b86cf25589..50f52507f4 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -7153,7 +7153,7 @@ compile(MyThread* t, Context* context) unsigned index = methodParameterFootprint(t, context->method); if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { frame.set(--index, Frame::Object); - c->initLocal(1, index, Compiler::ObjectType); + c->initLocal(1, index, frame.types.object); } for (MethodSpecIterator it @@ -7165,29 +7165,29 @@ compile(MyThread* t, Context* context) case 'L': case '[': frame.set(--index, Frame::Object); - c->initLocal(1, index, Compiler::ObjectType); + c->initLocal(1, index, frame.types.object); break; - + case 'J': frame.set(--index, Frame::Long); frame.set(--index, Frame::Long); - c->initLocal(2, index, Compiler::IntegerType); + c->initLocal(2, index, frame.types.i8); break; case 'D': frame.set(--index, Frame::Long); frame.set(--index, Frame::Long); - c->initLocal(2, index, Compiler::FloatType); + c->initLocal(2, index, frame.types.f8); break; - + case 'F': frame.set(--index, Frame::Integer); - c->initLocal(1, index, Compiler::FloatType); + c->initLocal(1, index, frame.types.f4); break; - + default: frame.set(--index, Frame::Integer); - c->initLocal(1, index, Compiler::IntegerType); + c->initLocal(1, index, frame.types.i4); break; } } From 704c05f818185fe92237fa53a2dbc6b0b14f22e8 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 21:54:52 -0600 Subject: [PATCH 09/89] use ir::Type in place of Compiler::OperandType --- include/avian/codegen/compiler.h | 20 +- include/avian/codegen/ir.h | 11 +- src/codegen/compiler.cpp | 41 +- src/compile.cpp | 1381 +++++++++++++++++------------- 4 files changed, 802 insertions(+), 651 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index e43edb75b1..c8375f49c6 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -34,20 +34,12 @@ class Compiler { virtual intptr_t getThunk(lir::TernaryOperation op, unsigned size, unsigned resultSize, bool* threadParameter) = 0; }; - + static const unsigned Aligned = 1 << 0; static const unsigned NoReturn = 1 << 1; static const unsigned TailJump = 1 << 2; static const unsigned LongJumpOrCall = 1 << 3; - enum OperandType { - ObjectType, - AddressType, - IntegerType, - FloatType, - VoidType - }; - class Operand { }; class State { }; class Subroutine { }; @@ -71,11 +63,11 @@ class Compiler { virtual Promise* poolAppend(intptr_t value) = 0; virtual Promise* poolAppendPromise(Promise* value) = 0; - virtual Operand* constant(int64_t value, OperandType type) = 0; - virtual Operand* promiseConstant(Promise* value, OperandType type) = 0; + virtual Operand* constant(int64_t value, ir::Type type) = 0; + virtual Operand* promiseConstant(Promise* value, ir::Type type) = 0; virtual Operand* address(Promise* address) = 0; virtual Operand* memory(Operand* base, - OperandType type, + ir::Type type, int displacement = 0, Operand* index = 0, unsigned scale = 1) = 0; @@ -94,7 +86,7 @@ class Compiler { unsigned flags, TraceHandler* traceHandler, unsigned resultSize, - OperandType resultType, + ir::Type resultType, unsigned argumentCount, ...) = 0; @@ -102,7 +94,7 @@ class Compiler { unsigned flags, TraceHandler* traceHandler, unsigned resultSize, - OperandType resultType, + ir::Type resultType, unsigned argumentFootprint) = 0; virtual void return_(ir::Type type, Operand* value) = 0; diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h index 8ed577b91c..09810b5b08 100644 --- a/include/avian/codegen/ir.h +++ b/include/avian/codegen/ir.h @@ -30,6 +30,10 @@ class Type { // (double/long on 32-bit systems) // TODO: remove when possible Half, + + // Represents the lack of a return value + // TODO: remove when possible + Void }; private: @@ -91,6 +95,10 @@ class Types { // A 8-byte floating point type Type f8; + // A type representing the lack of a return value + // TODO: remove when possible + Type void_; + Types(unsigned bytesPerWord) : object(Type::Object, bytesPerWord), address(Type::Integer, bytesPerWord), @@ -99,7 +107,8 @@ class Types { i4(Type::Integer, 4), i8(Type::Integer, 8), f4(Type::Float, 4), - f8(Type::Float, 8) + f8(Type::Float, 8), + void_(Type::Void, 0) { } }; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index af0ce8abdc..496f29e2a3 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -156,7 +156,7 @@ popRead(Context* c, Event* e UNUSED, Value* v) if (valid(nextWord->reads)) { deadWord(c, v); } else { - deadWord(c, nextWord); + deadWord(c, nextWord); } } @@ -186,22 +186,6 @@ addBuddy(Value* original, Value* buddy) } } -lir::ValueType -valueType(Context* c, Compiler::OperandType type) -{ - switch (type) { - case Compiler::ObjectType: - case Compiler::AddressType: - case Compiler::IntegerType: - case Compiler::VoidType: - return lir::ValueGeneral; - case Compiler::FloatType: - return lir::ValueFloat; - default: - abort(c); - } -} - void move(Context* c, Value* value, Site* src, Site* dst); @@ -2121,6 +2105,8 @@ unsigned typeFootprint(Context* c, ir::Type type) case ir::Type::Address: case ir::Type::Half: return 1; + case ir::Type::Void: + return 0; default: abort(c); } @@ -2306,13 +2292,14 @@ class MyCompiler: public Compiler { return p; } - virtual Operand* constant(int64_t value, Compiler::OperandType type) { + virtual Operand* constant(int64_t value, ir::Type type) + { return promiseConstant(resolvedPromise(&c, value), type); } - virtual Operand* promiseConstant(Promise* value, Compiler::OperandType type) { - return compiler::value - (&c, valueType(&c, type), compiler::constantSite(&c, value)); + virtual Operand* promiseConstant(Promise* value, ir::Type type) + { + return compiler::value(&c, type, compiler::constantSite(&c, value)); } virtual Operand* address(Promise* address) { @@ -2320,12 +2307,12 @@ class MyCompiler: public Compiler { } virtual Operand* memory(Operand* base, - OperandType type, + ir::Type type, int displacement = 0, Operand* index = 0, unsigned scale = 1) { - Value* result = value(&c, valueType(&c, type)); + Value* result = value(&c, type); appendMemory(&c, static_cast(base), displacement, static_cast(index), scale, result); @@ -2441,7 +2428,7 @@ class MyCompiler: public Compiler { unsigned flags, TraceHandler* traceHandler, unsigned resultSize, - OperandType resultType, + ir::Type resultType, unsigned argumentCount, ...) { @@ -2479,7 +2466,7 @@ class MyCompiler: public Compiler { (&c, RUNTIME_ARRAY_BODY(arguments)[i], argumentStack); } - Value* result = value(&c, valueType(&c, resultType)); + Value* result = value(&c, resultType); appendCall(&c, static_cast(address), flags, traceHandler, result, resultSize, argumentStack, index, 0); @@ -2490,10 +2477,10 @@ class MyCompiler: public Compiler { unsigned flags, TraceHandler* traceHandler, unsigned resultSize, - OperandType resultType, + ir::Type resultType, unsigned argumentFootprint) { - Value* result = value(&c, valueType(&c, resultType)); + Value* result = value(&c, resultType); appendCall(&c, static_cast(address), flags, traceHandler, result, resultSize, c.stack, 0, argumentFootprint); return result; diff --git a/src/compile.cpp b/src/compile.cpp index 50f52507f4..360be4a5ba 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1411,10 +1411,11 @@ class Frame { bc->constants = makeTriple(t, o, pointer, bc->constants); return c->binaryOp(lir::Add, - TargetBytesPerWord, c->memory - (c->register_(t->arch->thread()), Compiler::AddressType, - TARGET_THREAD_HEAPIMAGE), c->promiseConstant - (p, Compiler::AddressType)); + TargetBytesPerWord, + c->memory(c->register_(t->arch->thread()), + types.address, + TARGET_THREAD_HEAPIMAGE), + c->promiseConstant(p, types.address)); } else { for (PoolElement* e = context->objectPool; e; e = e->next) { if (o == e->target) { @@ -1635,7 +1636,7 @@ class Frame { } Value addressOperand(avian::codegen::Promise* p) { - return c->promiseConstant(p, Compiler::AddressType); + return c->promiseConstant(p, types.address); } Value absoluteAddressOperand(avian::codegen::Promise* p) { @@ -1644,19 +1645,19 @@ class Frame { lir::Add, TargetBytesPerWord, c->memory(c->register_(t->arch->thread()), - Compiler::AddressType, + types.address, TARGET_THREAD_CODEIMAGE), c->promiseConstant( new (&context->zone) avian::codegen::OffsetPromise( p, -reinterpret_cast( codeAllocator(t)->memory.begin())), - Compiler::AddressType)) + types.address)) : addressOperand(p); } Value machineIp(unsigned logicalIp) { - return c->promiseConstant(c->machineIp(logicalIp), Compiler::AddressType); + return c->promiseConstant(c->machineIp(logicalIp), types.address); } void visitLogicalIp(unsigned ip) { @@ -3105,27 +3106,32 @@ popField(MyThread* t, Frame* frame, int code) } } -Compiler::OperandType -operandTypeForFieldCode(Thread* t, unsigned code) +ir::Type operandTypeForFieldCode(Thread* t, unsigned code) { + ir::Types types(TargetBytesPerWord); + switch (code) { case ByteField: case BooleanField: + return types.i1; case CharField: case ShortField: + return types.i2; case IntField: + return types.i4; case LongField: - return Compiler::IntegerType; + return types.i8; case ObjectField: - return Compiler::ObjectType; + return types.address; case FloatField: + return types.f4; case DoubleField: - return Compiler::FloatType; + return types.f8; case VoidField: - return Compiler::VoidType; + return types.void_; default: abort(t); @@ -3147,13 +3153,14 @@ useLongJump(MyThread* t, uintptr_t target) } void compileSafePoint(MyThread* t, Compiler* c, Frame* frame) { - c->call - (c->constant(getThunk(t, idleIfNecessaryThunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - 0, - Compiler::VoidType, - 1, c->register_(t->arch->thread())); + ir::Types types(TargetBytesPerWord); + c->call(c->constant(getThunk(t, idleIfNecessaryThunk), types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 1, + c->register_(t->arch->thread())); } Compiler::Operand* @@ -3161,6 +3168,7 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall, bool useThunk, unsigned rSize, avian::codegen::Promise* addressPromise) { avian::codegen::Compiler* c = frame->c; + ir::Types types(TargetBytesPerWord); unsigned flags = (avian::codegen::TailCalls and tailCall ? Compiler::TailJump : 0); unsigned traceFlags; @@ -3188,42 +3196,41 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall, (frame->context->zone.allocate(sizeof(TraceElementPromise))) TraceElementPromise(t->m->system, trace); - Compiler::Operand* result = c->stackCall - (c->promiseConstant(returnAddressPromise, Compiler::AddressType), - flags, - trace, - rSize, - operandTypeForFieldCode(t, methodReturnCode(t, target)), - methodParameterFootprint(t, target)); + Compiler::Operand* result = c->stackCall( + c->promiseConstant(returnAddressPromise, types.address), + flags, + trace, + rSize, + operandTypeForFieldCode(t, methodReturnCode(t, target)), + methodParameterFootprint(t, target)); - c->store - (TargetBytesPerWord, - frame->absoluteAddressOperand(returnAddressPromise), - TargetBytesPerWord, c->memory - (c->register_(t->arch->thread()), Compiler::AddressType, - TARGET_THREAD_TAILADDRESS)); + c->store(TargetBytesPerWord, + frame->absoluteAddressOperand(returnAddressPromise), + TargetBytesPerWord, + c->memory(c->register_(t->arch->thread()), + types.address, + TARGET_THREAD_TAILADDRESS)); - c->exit - (c->constant - ((methodFlags(t, target) & ACC_NATIVE) - ? nativeThunk(t) : defaultThunk(t), - Compiler::AddressType)); + c->exit(c->constant((methodFlags(t, target) & ACC_NATIVE) + ? nativeThunk(t) + : defaultThunk(t), + types.address)); return result; } else { - return c->stackCall - (c->constant(defaultThunk(t), Compiler::AddressType), - flags, - frame->trace(target, traceFlags), - rSize, - operandTypeForFieldCode(t, methodReturnCode(t, target)), - methodParameterFootprint(t, target)); + return c->stackCall( + c->constant(defaultThunk(t), types.address), + flags, + frame->trace(target, traceFlags), + rSize, + operandTypeForFieldCode(t, methodReturnCode(t, target)), + methodParameterFootprint(t, target)); } } else { - Compiler::Operand* address = - (addressPromise - ? c->promiseConstant(addressPromise, Compiler::AddressType) - : c->constant(methodAddress(t, target), Compiler::AddressType)); + Compiler::Operand* address + = (addressPromise + ? c->promiseConstant(addressPromise, types.address) + : c->constant(methodAddress(t, target), types.address)); return c->stackCall (address, @@ -3342,20 +3349,25 @@ compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk, object reference, bool isStatic, bool tailCall) { avian::codegen::Compiler* c = frame->c; + ir::Types types(TargetBytesPerWord); PROTECT(t, reference); object pair = makePair(t, frame->context->method, reference); - compileReferenceInvoke - (t, frame, c->call - (c->constant(getThunk(t, thunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - TargetBytesPerWord, - Compiler::AddressType, - 2, c->register_(t->arch->thread()), frame->append(pair)), - reference, isStatic, tailCall); + compileReferenceInvoke(t, + frame, + c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + TargetBytesPerWord, + types.address, + 2, + c->register_(t->arch->thread()), + frame->append(pair)), + reference, + isStatic, + tailCall); } void @@ -3363,7 +3375,8 @@ compileAbstractInvoke(MyThread* t, Frame* frame, Compiler::Operand* method, object target, bool tailCall) { unsigned parameterFootprint = methodParameterFootprint(t, target); - + ir::Types types(TargetBytesPerWord); + int returnCode = methodReturnCode(t, target); unsigned rSize = resultSize(t, returnCode); @@ -3388,21 +3401,26 @@ compileDirectAbstractInvoke(MyThread* t, Frame* frame, Thunk thunk, object target, bool tailCall) { avian::codegen::Compiler* c = frame->c; + ir::Types types(TargetBytesPerWord); - compileAbstractInvoke - (t, frame, c->call - (c->constant(getThunk(t, thunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - TargetBytesPerWord, - Compiler::AddressType, - 2, c->register_(t->arch->thread()), frame->append(target)), - target, tailCall); + compileAbstractInvoke(t, + frame, + c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + TargetBytesPerWord, + types.address, + 2, + c->register_(t->arch->thread()), + frame->append(target)), + target, + tailCall); } void handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) { + ir::Types types(TargetBytesPerWord); avian::codegen::Compiler* c = frame->c; object method = frame->context->method; @@ -3415,13 +3433,15 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) } else { lock = loadLocal(frame->context, 1, savedTargetIndex(t, method)); } - - c->call(c->constant(function, Compiler::AddressType), + + c->call(c->constant(function, types.address), 0, frame->trace(0, 0), 0, - Compiler::VoidType, - 2, c->register_(t->arch->thread()), lock); + types.void_, + 2, + c->register_(t->arch->thread()), + lock); } } @@ -3700,6 +3720,7 @@ popLongAddress(Frame* frame) bool intrinsic(MyThread* t, Frame* frame, object target) { + ir::Types types(TargetBytesPerWord); #define MATCH(name, constant) \ (byteArrayLength(t, name) == sizeof(constant) \ and ::strcmp(reinterpret_cast(&byteArrayBody(t, name, 0)), \ @@ -3732,10 +3753,8 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushInt - (c->load - (1, 1, c->memory(address, Compiler::IntegerType, 0, 0, 1), - TargetBytesPerWord)); + frame->pushInt(c->load( + 1, 1, c->memory(address, types.i4, 0, 0, 1), TargetBytesPerWord)); return true; } else if (MATCH(methodName(t, target), "putByte") and MATCH(methodSpec(t, target), "(JB)V")) @@ -3743,9 +3762,8 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store - (TargetBytesPerWord, value, 1, c->memory - (address, Compiler::IntegerType, 0, 0, 1)); + c->store( + TargetBytesPerWord, value, 1, c->memory(address, types.i4, 0, 0, 1)); return true; } else if ((MATCH(methodName(t, target), "getShort") and MATCH(methodSpec(t, target), "(J)S")) @@ -3754,10 +3772,8 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushInt - (c->load - (2, 2, c->memory(address, Compiler::IntegerType, 0, 0, 1), - TargetBytesPerWord)); + frame->pushInt(c->load( + 2, 2, c->memory(address, types.i4, 0, 0, 1), TargetBytesPerWord)); return true; } else if ((MATCH(methodName(t, target), "putShort") and MATCH(methodSpec(t, target), "(JS)V")) @@ -3767,9 +3783,8 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store - (TargetBytesPerWord, value, 2, c->memory - (address, Compiler::IntegerType, 0, 0, 1)); + c->store( + TargetBytesPerWord, value, 2, c->memory(address, types.i4, 0, 0, 1)); return true; } else if ((MATCH(methodName(t, target), "getInt") and MATCH(methodSpec(t, target), "(J)I")) @@ -3778,12 +3793,16 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushInt - (c->load - (4, 4, c->memory - (address, MATCH(methodName(t, target), "getInt") - ? Compiler::IntegerType : Compiler::FloatType, 0, 0, 1), - TargetBytesPerWord)); + frame->pushInt( + c->load(4, + 4, + c->memory(address, + MATCH(methodName(t, target), "getInt") ? types.i4 + : types.f4, + 0, + 0, + 1), + TargetBytesPerWord)); return true; } else if ((MATCH(methodName(t, target), "putInt") and MATCH(methodSpec(t, target), "(JI)V")) @@ -3793,10 +3812,15 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store - (TargetBytesPerWord, value, 4, c->memory - (address, MATCH(methodName(t, target), "putInt") - ? Compiler::IntegerType : Compiler::FloatType, 0, 0, 1)); + c->store(TargetBytesPerWord, + value, + 4, + c->memory( + address, + MATCH(methodName(t, target), "putInt") ? types.i4 : types.f4, + 0, + 0, + 1)); return true; } else if ((MATCH(methodName(t, target), "getLong") and MATCH(methodSpec(t, target), "(J)J")) @@ -3805,12 +3829,16 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushLong - (c->load - (8, 8, c->memory - (address, MATCH(methodName(t, target), "getLong") - ? Compiler::IntegerType : Compiler::FloatType, 0, 0, 1), - 8)); + frame->pushLong( + c->load(8, + 8, + c->memory(address, + MATCH(methodName(t, target), "getLong") ? types.i4 + : types.f4, + 0, + 0, + 1), + 8)); return true; } else if ((MATCH(methodName(t, target), "putLong") and MATCH(methodSpec(t, target), "(JJ)V")) @@ -3820,20 +3848,25 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popLong(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store - (8, value, 8, c->memory - (address, MATCH(methodName(t, target), "putLong") - ? Compiler::IntegerType : Compiler::FloatType, 0, 0, 1)); + c->store(8, + value, + 8, + c->memory(address, + MATCH(methodName(t, target), "putLong") ? types.i4 + : types.f4, + 0, + 0, + 1)); return true; } else if (MATCH(methodName(t, target), "getAddress") and MATCH(methodSpec(t, target), "(J)J")) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushLong - (c->load - (TargetBytesPerWord, TargetBytesPerWord, - c->memory(address, Compiler::AddressType, 0, 0, 1), 8)); + frame->pushLong(c->load(TargetBytesPerWord, + TargetBytesPerWord, + c->memory(address, types.address, 0, 0, 1), + 8)); return true; } else if (MATCH(methodName(t, target), "putAddress") and MATCH(methodSpec(t, target), "(JJ)V")) @@ -3841,9 +3874,10 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popLong(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store - (8, value, TargetBytesPerWord, c->memory - (address, Compiler::AddressType, 0, 0, 1)); + c->store(8, + value, + TargetBytesPerWord, + c->memory(address, types.address, 0, 0, 1)); return true; } } @@ -4050,14 +4084,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, exceptionHandlerStart = -1; frame->pushObject(); - - c->call - (c->constant(getThunk(t, gcIfNecessaryThunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - 0, - Compiler::VoidType, - 1, c->register_(t->arch->thread())); + + c->call(c->constant(getThunk(t, gcIfNecessaryThunk), types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 1, + c->register_(t->arch->thread())); } // fprintf(stderr, "ip: %d map: %ld\n", ip, *(frame->map)); @@ -4087,66 +4121,64 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (instruction) { case aaload: - frame->pushObject - (c->load - (TargetBytesPerWord, TargetBytesPerWord, c->memory - (array, Compiler::ObjectType, TargetArrayBody, index, - TargetBytesPerWord), - TargetBytesPerWord)); + frame->pushObject(c->load(TargetBytesPerWord, + TargetBytesPerWord, + c->memory(array, + types.object, + TargetArrayBody, + index, + TargetBytesPerWord), + TargetBytesPerWord)); break; case faload: - frame->pushInt - (c->load - (4, 4, c->memory - (array, Compiler::FloatType, TargetArrayBody, index, 4), - TargetBytesPerWord)); + frame->pushInt( + c->load(4, + 4, + c->memory(array, types.f4, TargetArrayBody, index, 4), + TargetBytesPerWord)); break; case iaload: - frame->pushInt - (c->load - (4, 4, c->memory - (array, Compiler::IntegerType, TargetArrayBody, index, 4), - TargetBytesPerWord)); + frame->pushInt( + c->load(4, + 4, + c->memory(array, types.i4, TargetArrayBody, index, 4), + TargetBytesPerWord)); break; case baload: - frame->pushInt - (c->load - (1, 1, c->memory - (array, Compiler::IntegerType, TargetArrayBody, index, 1), - TargetBytesPerWord)); + frame->pushInt( + c->load(1, + 1, + c->memory(array, types.i4, TargetArrayBody, index, 1), + TargetBytesPerWord)); break; case caload: - frame->pushInt - (c->loadz - (2, 2, c->memory - (array, Compiler::IntegerType, TargetArrayBody, index, 2), - TargetBytesPerWord)); + frame->pushInt( + c->loadz(2, + 2, + c->memory(array, types.i4, TargetArrayBody, index, 2), + TargetBytesPerWord)); break; case daload: - frame->pushLong - (c->load - (8, 8, c->memory - (array, Compiler::FloatType, TargetArrayBody, index, 8), 8)); + frame->pushLong(c->load( + 8, 8, c->memory(array, types.f4, TargetArrayBody, index, 8), 8)); break; case laload: - frame->pushLong - (c->load - (8, 8, c->memory - (array, Compiler::IntegerType, TargetArrayBody, index, 8), 8)); + frame->pushLong(c->load( + 8, 8, c->memory(array, types.i4, TargetArrayBody, index, 8), 8)); break; case saload: - frame->pushInt - (c->load - (2, 2, c->memory - (array, Compiler::IntegerType, TargetArrayBody, index, 2), - TargetBytesPerWord)); + frame->pushInt( + c->load(2, + 2, + c->memory(array, types.i4, TargetArrayBody, index, 2), + TargetBytesPerWord)); break; } } break; @@ -4182,62 +4214,68 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (instruction) { case aastore: { - c->call - (c->constant(getThunk(t, setMaybeNullThunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - 0, - Compiler::VoidType, - 4, c->register_(t->arch->thread()), array, - c->binaryOp(lir::Add, - 4, c->constant(TargetArrayBody, Compiler::IntegerType), - c->binaryOp(lir::ShiftLeft, - 4, c->constant(log(TargetBytesPerWord), Compiler::IntegerType), - index)), - value); + c->call(c->constant(getThunk(t, setMaybeNullThunk), types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 4, + c->register_(t->arch->thread()), + array, + c->binaryOp( + lir::Add, + 4, + c->constant(TargetArrayBody, types.i4), + c->binaryOp(lir::ShiftLeft, + 4, + c->constant(log(TargetBytesPerWord), types.i4), + index)), + value); } break; case fastore: - c->store - (TargetBytesPerWord, value, 4, c->memory - (array, Compiler::FloatType, TargetArrayBody, index, 4)); + c->store(TargetBytesPerWord, + value, + 4, + c->memory(array, types.f4, TargetArrayBody, index, 4)); break; case iastore: - c->store - (TargetBytesPerWord, value, 4, c->memory - (array, Compiler::IntegerType, TargetArrayBody, index, 4)); + c->store(TargetBytesPerWord, + value, + 4, + c->memory(array, types.i4, TargetArrayBody, index, 4)); break; case bastore: - c->store - (TargetBytesPerWord, value, 1, c->memory - (array, Compiler::IntegerType, TargetArrayBody, index, 1)); + c->store(TargetBytesPerWord, + value, + 1, + c->memory(array, types.i4, TargetArrayBody, index, 1)); break; case castore: case sastore: - c->store - (TargetBytesPerWord, value, 2, c->memory - (array, Compiler::IntegerType, TargetArrayBody, index, 2)); + c->store(TargetBytesPerWord, + value, + 2, + c->memory(array, types.i4, TargetArrayBody, index, 2)); break; case dastore: - c->store - (8, value, 8, c->memory - (array, Compiler::FloatType, TargetArrayBody, index, 8)); + c->store( + 8, value, 8, c->memory(array, types.f4, TargetArrayBody, index, 8)); break; case lastore: - c->store - (8, value, 8, c->memory - (array, Compiler::IntegerType, TargetArrayBody, index, 8)); + c->store( + 8, value, 8, c->memory(array, types.i4, TargetArrayBody, index, 8)); break; } } break; case aconst_null: - frame->pushObject(c->constant(0, Compiler::ObjectType)); + frame->pushObject(c->constant(0, types.object)); break; case aload: @@ -4282,15 +4320,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, thunk = makeBlankObjectArrayFromReferenceThunk; } - frame->pushObject - (c->call - (c->constant(getThunk(t, thunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - TargetBytesPerWord, - Compiler::ObjectType, - 3, c->register_(t->arch->thread()), frame->append(argument), - length)); + frame->pushObject(c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + TargetBytesPerWord, + types.object, + 3, + c->register_(t->arch->thread()), + frame->append(argument), + length)); } break; case areturn: { @@ -4299,12 +4337,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto next; case arraylength: { - frame->pushInt - (c->load - (TargetBytesPerWord, TargetBytesPerWord, - c->memory - (frame->popObject(), Compiler::IntegerType, - TargetArrayLength, 0, 1), + frame->pushInt(c->load( + TargetBytesPerWord, + TargetBytesPerWord, + c->memory(frame->popObject(), types.i4, TargetArrayLength, 0, 1), TargetBytesPerWord)); } break; @@ -4330,22 +4366,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case athrow: { Compiler::Operand* target = frame->popObject(); - c->call - (c->constant(getThunk(t, throw_Thunk), Compiler::AddressType), - Compiler::NoReturn, - frame->trace(0, 0), - 0, - Compiler::VoidType, - 2, c->register_(t->arch->thread()), target); + c->call(c->constant(getThunk(t, throw_Thunk), types.address), + Compiler::NoReturn, + frame->trace(0, 0), + 0, + types.void_, + 2, + c->register_(t->arch->thread()), + target); c->nullaryOp(lir::Trap); } goto next; case bipush: - frame->pushInt - (c->constant - (static_cast(codeBody(t, code, ip++)), - Compiler::IntegerType)); + frame->pushInt( + c->constant(static_cast(codeBody(t, code, ip++)), types.i4)); break; case checkcast: { @@ -4370,14 +4405,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* instance = c->peek(1, 0); - c->call - (c->constant(getThunk(t, thunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - 0, - Compiler::VoidType, - 3, c->register_(t->arch->thread()), frame->append(argument), - instance); + c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 3, + c->register_(t->arch->thread()), + frame->append(argument), + instance); } break; case d2f: { @@ -4410,13 +4446,17 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (floatBranch(t, frame, code, ip, 8, false, a, b, &newIp)) { goto branch; } else { - frame->pushInt - (c->call - (c->constant - (getThunk(t, compareDoublesGThunk), Compiler::AddressType), - 0, 0, 4, Compiler::IntegerType, 4, - static_cast(0), a, - static_cast(0), b)); + frame->pushInt(c->call( + c->constant(getThunk(t, compareDoublesGThunk), types.address), + 0, + 0, + 4, + types.i4, + 4, + static_cast(0), + a, + static_cast(0), + b)); } } break; @@ -4427,22 +4467,26 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (floatBranch(t, frame, code, ip, 8, true, a, b, &newIp)) { goto branch; } else { - frame->pushInt - (c->call - (c->constant - (getThunk(t, compareDoublesLThunk), Compiler::AddressType), - 0, 0, 4, Compiler::IntegerType, 4, - static_cast(0), a, - static_cast(0), b)); + frame->pushInt(c->call( + c->constant(getThunk(t, compareDoublesLThunk), types.address), + 0, + 0, + 4, + types.i4, + 4, + static_cast(0), + a, + static_cast(0), + b)); } } break; case dconst_0: - frame->pushLong(c->constant(doubleToBits(0.0), Compiler::FloatType)); + frame->pushLong(c->constant(doubleToBits(0.0), types.f4)); break; case dconst_1: - frame->pushLong(c->constant(doubleToBits(1.0), Compiler::FloatType)); + frame->pushLong(c->constant(doubleToBits(1.0), types.f4)); break; case dneg: { @@ -4503,11 +4547,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (floatBranch(t, frame, code, ip, 4, false, a, b, &newIp)) { goto branch; } else { - frame->pushInt - (c->call - (c->constant - (getThunk(t, compareFloatsGThunk), Compiler::AddressType), - 0, 0, 4, Compiler::IntegerType, 2, a, b)); + frame->pushInt(c->call( + c->constant(getThunk(t, compareFloatsGThunk), types.address), + 0, + 0, + 4, + types.i4, + 2, + a, + b)); } } break; @@ -4518,24 +4566,28 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (floatBranch(t, frame, code, ip, 4, true, a, b, &newIp)) { goto branch; } else { - frame->pushInt - (c->call - (c->constant - (getThunk(t, compareFloatsLThunk), Compiler::AddressType), - 0, 0, 4, Compiler::IntegerType, 2, a, b)); + frame->pushInt(c->call( + c->constant(getThunk(t, compareFloatsLThunk), types.address), + 0, + 0, + 4, + types.i4, + 2, + a, + b)); } } break; case fconst_0: - frame->pushInt(c->constant(floatToBits(0.0), Compiler::FloatType)); + frame->pushInt(c->constant(floatToBits(0.0), types.f4)); break; case fconst_1: - frame->pushInt(c->constant(floatToBits(1.0), Compiler::FloatType)); + frame->pushInt(c->constant(floatToBits(1.0), types.f4)); break; case fconst_2: - frame->pushInt(c->constant(floatToBits(2.0), Compiler::FloatType)); + frame->pushInt(c->constant(floatToBits(2.0), types.f4)); break; case fneg: { @@ -4561,13 +4613,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, { PROTECT(t, field); - c->call - (c->constant - (getThunk(t, acquireMonitorForObjectThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), 0, Compiler::VoidType, 2, - c->register_(t->arch->thread()), - frame->append(field)); + c->call(c->constant(getThunk(t, acquireMonitorForObjectThunk), + types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 2, + c->register_(t->arch->thread()), + frame->append(field)); } Compiler::Operand* table; @@ -4578,15 +4632,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, PROTECT(t, field); if (classNeedsInit(t, fieldClass(t, field))) { - c->call - (c->constant - (getThunk(t, tryInitClassThunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - 0, - Compiler::VoidType, - 2, c->register_(t->arch->thread()), - frame->append(fieldClass(t, field))); + c->call(c->constant(getThunk(t, tryInitClassThunk), types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 2, + c->register_(t->arch->thread()), + frame->append(fieldClass(t, field))); } table = frame->append(classStaticTable(t, fieldClass(t, field))); @@ -4604,68 +4657,75 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (fieldCode(t, field)) { case ByteField: case BooleanField: - frame->pushInt - (c->load - (1, 1, c->memory - (table, Compiler::IntegerType, targetFieldOffset - (context, field), 0, 1), TargetBytesPerWord)); + frame->pushInt(c->load( + 1, + 1, + c->memory( + table, types.i4, targetFieldOffset(context, field), 0, 1), + TargetBytesPerWord)); break; case CharField: - frame->pushInt - (c->loadz - (2, 2, c->memory - (table, Compiler::IntegerType, targetFieldOffset - (context, field), 0, 1), TargetBytesPerWord)); + frame->pushInt(c->loadz( + 2, + 2, + c->memory( + table, types.i4, targetFieldOffset(context, field), 0, 1), + TargetBytesPerWord)); break; case ShortField: - frame->pushInt - (c->load - (2, 2, c->memory - (table, Compiler::IntegerType, targetFieldOffset - (context, field), 0, 1), TargetBytesPerWord)); + frame->pushInt(c->load( + 2, + 2, + c->memory( + table, types.i4, targetFieldOffset(context, field), 0, 1), + TargetBytesPerWord)); break; case FloatField: - frame->pushInt - (c->load - (4, 4, c->memory - (table, Compiler::FloatType, targetFieldOffset - (context, field), 0, 1), TargetBytesPerWord)); + frame->pushInt(c->load( + 4, + 4, + c->memory( + table, types.f4, targetFieldOffset(context, field), 0, 1), + TargetBytesPerWord)); break; case IntField: - frame->pushInt - (c->load - (4, 4, c->memory - (table, Compiler::IntegerType, targetFieldOffset - (context, field), 0, 1), TargetBytesPerWord)); + frame->pushInt(c->load( + 4, + 4, + c->memory( + table, types.i4, targetFieldOffset(context, field), 0, 1), + TargetBytesPerWord)); break; case DoubleField: - frame->pushLong - (c->load - (8, 8, c->memory - (table, Compiler::FloatType, targetFieldOffset - (context, field), 0, 1), 8)); + frame->pushLong(c->load( + 8, + 8, + c->memory( + table, types.f4, targetFieldOffset(context, field), 0, 1), + 8)); break; case LongField: - frame->pushLong - (c->load - (8, 8, c->memory - (table, Compiler::IntegerType, targetFieldOffset - (context, field), 0, 1), 8)); + frame->pushLong(c->load( + 8, + 8, + c->memory( + table, types.i4, targetFieldOffset(context, field), 0, 1), + 8)); break; case ObjectField: - frame->pushObject - (c->load - (TargetBytesPerWord, TargetBytesPerWord, - c->memory - (table, Compiler::ObjectType, targetFieldOffset - (context, field), 0, 1), TargetBytesPerWord)); + frame->pushObject(c->load( + TargetBytesPerWord, + TargetBytesPerWord, + c->memory( + table, types.object, targetFieldOffset(context, field), 0, 1), + TargetBytesPerWord)); break; default: @@ -4677,13 +4737,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, and (fieldCode(t, field) == DoubleField or fieldCode(t, field) == LongField)) { - c->call - (c->constant - (getThunk(t, releaseMonitorForObjectThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), 0, Compiler::VoidType, 2, - c->register_(t->arch->thread()), - frame->append(field)); + c->call(c->constant(getThunk(t, releaseMonitorForObjectThunk), + types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 2, + c->register_(t->arch->thread()), + frame->append(field)); } else { c->nullaryOp(lir::LoadBarrier); } @@ -4695,26 +4757,34 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, object pair = makePair(t, context->method, reference); unsigned rSize = resultSize(t, fieldCode); - Compiler::OperandType rType = operandTypeForFieldCode(t, fieldCode); + ir::Type rType = operandTypeForFieldCode(t, fieldCode); Compiler::Operand* result; if (instruction == getstatic) { - result = c->call - (c->constant - (getThunk(t, getStaticFieldValueFromReferenceThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), rSize, rType, 2, - c->register_(t->arch->thread()), frame->append(pair)); + result = c->call( + c->constant(getThunk(t, getStaticFieldValueFromReferenceThunk), + types.address), + 0, + frame->trace(0, 0), + rSize, + rType, + 2, + c->register_(t->arch->thread()), + frame->append(pair)); } else { Compiler::Operand* instance = frame->popObject(); - result = c->call - (c->constant - (getThunk(t, getFieldValueFromReferenceThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), rSize, rType, 3, - c->register_(t->arch->thread()), frame->append(pair), - instance); + result = c->call( + c->constant(getThunk(t, getFieldValueFromReferenceThunk), + types.address), + 0, + frame->trace(0, 0), + rSize, + rType, + 3, + c->register_(t->arch->thread()), + frame->append(pair), + instance); } pushReturnValue(t, frame, fieldCode, result); @@ -4789,31 +4859,31 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case iconst_m1: - frame->pushInt(c->constant(-1, Compiler::IntegerType)); + frame->pushInt(c->constant(-1, types.i4)); break; case iconst_0: - frame->pushInt(c->constant(0, Compiler::IntegerType)); + frame->pushInt(c->constant(0, types.i4)); break; case iconst_1: - frame->pushInt(c->constant(1, Compiler::IntegerType)); + frame->pushInt(c->constant(1, types.i4)); break; case iconst_2: - frame->pushInt(c->constant(2, Compiler::IntegerType)); + frame->pushInt(c->constant(2, types.i4)); break; case iconst_3: - frame->pushInt(c->constant(3, Compiler::IntegerType)); + frame->pushInt(c->constant(3, types.i4)); break; case iconst_4: - frame->pushInt(c->constant(4, Compiler::IntegerType)); + frame->pushInt(c->constant(4, types.i4)); break; case iconst_5: - frame->pushInt(c->constant(5, Compiler::IntegerType)); + frame->pushInt(c->constant(5, types.i4)); break; case idiv: { @@ -4882,7 +4952,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - Compiler::Operand* a = c->constant(0, Compiler::IntegerType); + Compiler::Operand* a = c->constant(0, types.i4); Compiler::Operand* b = frame->popInt(); c->condJump(toCompilerJumpOp(t, instruction), 4, a, b, target); @@ -4898,7 +4968,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - Compiler::Operand* a = c->constant(0, Compiler::ObjectType); + Compiler::Operand* a = c->constant(0, types.object); Compiler::Operand* b = frame->popObject(); Compiler::Operand* target = frame->machineIp(newIp); @@ -4909,12 +4979,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint8_t index = codeBody(t, code, ip++); int8_t count = codeBody(t, code, ip++); - storeLocal - (context, 1, - c->binaryOp(lir::Add, - 4, c->constant(count, Compiler::IntegerType), - loadLocal(context, 1, index)), - index); + storeLocal(context, + 1, + c->binaryOp(lir::Add, + 4, + c->constant(count, types.i4), + loadLocal(context, 1, index)), + index); } break; case iload: @@ -4968,12 +5039,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, thunk = instanceOfFromReferenceThunk; } - frame->pushInt - (c->call - (c->constant(getThunk(t, thunk), Compiler::AddressType), - 0, frame->trace(0, 0), 4, Compiler::IntegerType, - 3, c->register_(t->arch->thread()), frame->append(argument), - instance)); + frame->pushInt(c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + 4, + types.i4, + 3, + c->register_(t->arch->thread()), + frame->append(argument), + instance)); } break; case invokeinterface: { @@ -5014,20 +5088,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, unsigned rSize = resultSize(t, returnCode); - Compiler::Operand* result = c->stackCall - (c->call - (c->constant(getThunk(t, thunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - TargetBytesPerWord, - Compiler::AddressType, - 3, c->register_(t->arch->thread()), frame->append(argument), - c->peek(1, parameterFootprint - 1)), - tailCall ? Compiler::TailJump : 0, - frame->trace(0, 0), - rSize, - operandTypeForFieldCode(t, returnCode), - parameterFootprint); + Compiler::Operand* result + = c->stackCall(c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + TargetBytesPerWord, + types.address, + 3, + c->register_(t->arch->thread()), + frame->append(argument), + c->peek(1, parameterFootprint - 1)), + tailCall ? Compiler::TailJump : 0, + frame->trace(0, 0), + rSize, + operandTypeForFieldCode(t, returnCode), + parameterFootprint); frame->pop(parameterFootprint); @@ -5125,18 +5200,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, unsigned rSize = resultSize(t, methodReturnCode(t, target)); - Compiler::Operand* result = c->stackCall - (c->memory - (c->binaryOp(lir::And, - TargetBytesPerWord, c->constant - (TargetPointerMask, Compiler::IntegerType), - c->memory(instance, Compiler::ObjectType, 0, 0, 1)), - Compiler::ObjectType, offset, 0, 1), - tailCall ? Compiler::TailJump : 0, - frame->trace(0, 0), - rSize, - operandTypeForFieldCode(t, methodReturnCode(t, target)), - parameterFootprint); + Compiler::Operand* result = c->stackCall( + c->memory( + c->binaryOp(lir::And, + TargetBytesPerWord, + c->constant(TargetPointerMask, types.i4), + c->memory(instance, types.object, 0, 0, 1)), + types.object, + offset, + 0, + 1), + tailCall ? Compiler::TailJump : 0, + frame->trace(0, 0), + rSize, + operandTypeForFieldCode(t, methodReturnCode(t, target)), + parameterFootprint); frame->pop(parameterFootprint); @@ -5156,19 +5234,25 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, object pair = makePair(t, context->method, reference); - compileReferenceInvoke - (t, frame, c->call - (c->constant(getThunk(t, findVirtualMethodFromReferenceThunk), - Compiler::AddressType), - 0, - frame->trace(0, 0), - TargetBytesPerWord, - Compiler::AddressType, - 3, c->register_(t->arch->thread()), frame->append(pair), - c->peek(1, methodReferenceParameterFootprint - (t, reference, false) - 1)), - reference, false, isReferenceTailCall - (t, code, ip, context->method, reference)); + compileReferenceInvoke( + t, + frame, + c->call( + c->constant(getThunk(t, findVirtualMethodFromReferenceThunk), + types.address), + 0, + frame->trace(0, 0), + TargetBytesPerWord, + types.address, + 3, + c->register_(t->arch->thread()), + frame->append(pair), + c->peek(1, + methodReferenceParameterFootprint(t, reference, false) + - 1)), + reference, + false, + isReferenceTailCall(t, code, ip, context->method, reference)); } } break; @@ -5276,22 +5360,26 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (integerBranch(t, frame, code, ip, 8, a, b, &newIp)) { goto branch; } else { - frame->pushInt - (c->call - (c->constant - (getThunk(t, compareLongsThunk), Compiler::AddressType), - 0, 0, 4, Compiler::IntegerType, 4, - static_cast(0), a, - static_cast(0), b)); + frame->pushInt( + c->call(c->constant(getThunk(t, compareLongsThunk), types.address), + 0, + 0, + 4, + types.i4, + 4, + static_cast(0), + a, + static_cast(0), + b)); } } break; case lconst_0: - frame->pushLong(c->constant(0, Compiler::IntegerType)); + frame->pushLong(c->constant(0, types.i4)); break; case lconst_1: - frame->pushLong(c->constant(1, Compiler::IntegerType)); + frame->pushLong(c->constant(1, types.i4)); break; case ldc: @@ -5318,41 +5406,39 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, v = resolveClassInPool(t, context->method, index - 1, false); if (UNLIKELY(v == 0)) { - frame->pushObject - (c->call - (c->constant - (getThunk(t, getJClassFromReferenceThunk), - Compiler::AddressType), + frame->pushObject(c->call( + c->constant(getThunk(t, getJClassFromReferenceThunk), + types.address), 0, frame->trace(0, 0), TargetBytesPerWord, - Compiler::ObjectType, - 2, c->register_(t->arch->thread()), + types.object, + 2, + c->register_(t->arch->thread()), frame->append(makePair(t, context->method, reference)))); } } if (v) { if (objectClass(t, v) == type(t, Machine::ClassType)) { - frame->pushObject - (c->call - (c->constant - (getThunk(t, getJClass64Thunk), Compiler::AddressType), + frame->pushObject(c->call( + c->constant(getThunk(t, getJClass64Thunk), types.address), 0, frame->trace(0, 0), TargetBytesPerWord, - Compiler::ObjectType, - 2, c->register_(t->arch->thread()), frame->append(v))); + types.object, + 2, + c->register_(t->arch->thread()), + frame->append(v))); } else { frame->pushObject(frame->append(v)); } } } else { - frame->pushInt - (c->constant - (singletonValue(t, pool, index - 1), - singletonBit(t, pool, poolSize(t, pool), index - 1) - ? Compiler::FloatType : Compiler::IntegerType)); + frame->pushInt(c->constant( + singletonValue(t, pool, index - 1), + singletonBit(t, pool, poolSize(t, pool), index - 1) ? types.f4 + : types.i4)); } } break; @@ -5363,10 +5449,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint64_t v; memcpy(&v, &singletonValue(t, pool, index - 1), 8); - frame->pushLong - (c->constant - (v, singletonBit(t, pool, poolSize(t, pool), index - 1) - ? Compiler::FloatType : Compiler::IntegerType)); + frame->pushLong(c->constant( + v, + singletonBit(t, pool, poolSize(t, pool), index - 1) ? types.f4 + : types.i4)); } break; case ldiv_: { @@ -5446,18 +5532,26 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } assert(t, start); - Compiler::Operand* address = c->call - (c->constant(getThunk(t, lookUpAddressThunk), Compiler::AddressType), - 0, 0, TargetBytesPerWord, Compiler::AddressType, - 4, key, frame->absoluteAddressOperand(start), - c->constant(pairCount, Compiler::IntegerType), default_); + Compiler::Operand* address = c->call( + c->constant(getThunk(t, lookUpAddressThunk), types.address), + 0, + 0, + TargetBytesPerWord, + types.address, + 4, + key, + frame->absoluteAddressOperand(start), + c->constant(pairCount, types.i4), + default_); - c->jmp - (context->bootContext ? c->binaryOp(lir::Add, - TargetBytesPerWord, c->memory - (c->register_(t->arch->thread()), Compiler::AddressType, - TARGET_THREAD_CODEIMAGE), address) - : address); + c->jmp(context->bootContext + ? c->binaryOp(lir::Add, + TargetBytesPerWord, + c->memory(c->register_(t->arch->thread()), + types.address, + TARGET_THREAD_CODEIMAGE), + address) + : address); new (stack.push(sizeof(SwitchState))) SwitchState (c->saveState(), pairCount, defaultIp, 0, 0, 0, 0); @@ -5528,20 +5622,28 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case monitorenter: { Compiler::Operand* target = frame->popObject(); - c->call - (c->constant - (getThunk(t, acquireMonitorForObjectThunk), Compiler::AddressType), - 0, frame->trace(0, 0), 0, Compiler::VoidType, 2, - c->register_(t->arch->thread()), target); + c->call( + c->constant(getThunk(t, acquireMonitorForObjectThunk), types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 2, + c->register_(t->arch->thread()), + target); } break; case monitorexit: { Compiler::Operand* target = frame->popObject(); - c->call - (c->constant - (getThunk(t, releaseMonitorForObjectThunk), Compiler::AddressType), - 0, frame->trace(0, 0), 0, Compiler::VoidType, 2, - c->register_(t->arch->thread()), target); + c->call( + c->constant(getThunk(t, releaseMonitorForObjectThunk), types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 2, + c->register_(t->arch->thread()), + target); } break; case multianewarray: { @@ -5570,16 +5672,17 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, (t, localSize(t, context->method) + c->topOfStack(), context->method) + t->arch->frameReturnAddressSize(); - Compiler::Operand* result = c->call - (c->constant - (getThunk(t, thunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - TargetBytesPerWord, - Compiler::ObjectType, - 4, c->register_(t->arch->thread()), frame->append(argument), - c->constant(dimensions, Compiler::IntegerType), - c->constant(offset, Compiler::IntegerType)); + Compiler::Operand* result + = c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + TargetBytesPerWord, + types.object, + 4, + c->register_(t->arch->thread()), + frame->append(argument), + c->constant(dimensions, types.i4), + c->constant(offset, types.i4)); frame->pop(dimensions); frame->pushObject(result); @@ -5609,14 +5712,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, thunk = makeNewFromReferenceThunk; } - frame->pushObject - (c->call - (c->constant(getThunk(t, thunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - TargetBytesPerWord, - Compiler::ObjectType, - 2, c->register_(t->arch->thread()), frame->append(argument))); + frame->pushObject(c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + TargetBytesPerWord, + types.object, + 2, + c->register_(t->arch->thread()), + frame->append(argument))); } break; case newarray: { @@ -5624,15 +5727,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* length = frame->popInt(); - frame->pushObject - (c->call - (c->constant(getThunk(t, makeBlankArrayThunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - TargetBytesPerWord, - Compiler::ObjectType, - 3, c->register_(t->arch->thread()), - c->constant(type, Compiler::IntegerType), length)); + frame->pushObject( + c->call(c->constant(getThunk(t, makeBlankArrayThunk), types.address), + 0, + frame->trace(0, 0), + TargetBytesPerWord, + types.object, + 3, + c->register_(t->arch->thread()), + c->constant(type, types.i4), + length)); } break; case nop: break; @@ -5667,15 +5771,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (classNeedsInit(t, fieldClass(t, field))) { PROTECT(t, field); - c->call - (c->constant - (getThunk(t, tryInitClassThunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - 0, - Compiler::VoidType, - 2, c->register_(t->arch->thread()), - frame->append(fieldClass(t, field))); + c->call(c->constant(getThunk(t, tryInitClassThunk), types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 2, + c->register_(t->arch->thread()), + frame->append(fieldClass(t, field))); } staticTable = classStaticTable(t, fieldClass(t, field)); @@ -5694,12 +5797,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, { PROTECT(t, field); - c->call - (c->constant - (getThunk(t, acquireMonitorForObjectThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), 0, Compiler::VoidType, 2, - c->register_(t->arch->thread()), frame->append(field)); + c->call(c->constant(getThunk(t, acquireMonitorForObjectThunk), + types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 2, + c->register_(t->arch->thread()), + frame->append(field)); } else { c->nullaryOp(lir::StoreStoreBarrier); } @@ -5720,69 +5826,83 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (fieldCode) { case ByteField: case BooleanField: - c->store - (TargetBytesPerWord, value, 1, c->memory - (table, Compiler::IntegerType, targetFieldOffset - (context, field), 0, 1)); + c->store( + TargetBytesPerWord, + value, + 1, + c->memory( + table, types.i4, targetFieldOffset(context, field), 0, 1)); break; case CharField: case ShortField: - c->store - (TargetBytesPerWord, value, 2, c->memory - (table, Compiler::IntegerType, targetFieldOffset - (context, field), 0, 1)); + c->store( + TargetBytesPerWord, + value, + 2, + c->memory( + table, types.i4, targetFieldOffset(context, field), 0, 1)); break; case FloatField: - c->store - (TargetBytesPerWord, value, 4, c->memory - (table, Compiler::FloatType, targetFieldOffset - (context, field), 0, 1)); + c->store( + TargetBytesPerWord, + value, + 4, + c->memory( + table, types.f4, targetFieldOffset(context, field), 0, 1)); break; case IntField: - c->store - (TargetBytesPerWord, value, 4, c->memory - (table, Compiler::IntegerType, targetFieldOffset - (context, field), 0, 1)); + c->store( + TargetBytesPerWord, + value, + 4, + c->memory( + table, types.i4, targetFieldOffset(context, field), 0, 1)); break; case DoubleField: - c->store - (8, value, 8, c->memory - (table, Compiler::FloatType, targetFieldOffset - (context, field), 0, 1)); + c->store( + 8, + value, + 8, + c->memory( + table, types.f4, targetFieldOffset(context, field), 0, 1)); break; case LongField: - c->store - (8, value, 8, c->memory - (table, Compiler::IntegerType, targetFieldOffset - (context, field), 0, 1)); + c->store( + 8, + value, + 8, + c->memory( + table, types.i4, targetFieldOffset(context, field), 0, 1)); break; case ObjectField: if (instruction == putfield) { - c->call - (c->constant - (getThunk(t, setMaybeNullThunk), Compiler::AddressType), - 0, - frame->trace(0, 0), - 0, - Compiler::VoidType, - 4, c->register_(t->arch->thread()), table, - c->constant(targetFieldOffset(context, field), - Compiler::IntegerType), - value); + c->call(c->constant(getThunk(t, setMaybeNullThunk), types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 4, + c->register_(t->arch->thread()), + table, + c->constant(targetFieldOffset(context, field), types.i4), + value); } else { - c->call - (c->constant(getThunk(t, setThunk), Compiler::AddressType), - 0, 0, 0, Compiler::VoidType, - 4, c->register_(t->arch->thread()), table, - c->constant(targetFieldOffset(context, field), - Compiler::IntegerType), - value); + c->call(c->constant(getThunk(t, setThunk), types.address), + 0, + 0, + 0, + types.void_, + 4, + c->register_(t->arch->thread()), + table, + c->constant(targetFieldOffset(context, field), types.i4), + value); } break; @@ -5793,12 +5913,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (TargetBytesPerWord == 4 and (fieldCode == DoubleField or fieldCode == LongField)) { - c->call - (c->constant - (getThunk(t, releaseMonitorForObjectThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), 0, Compiler::VoidType, 2, - c->register_(t->arch->thread()), frame->append(field)); + c->call(c->constant(getThunk(t, releaseMonitorForObjectThunk), + types.address), + 0, + frame->trace(0, 0), + 0, + types.void_, + 2, + c->register_(t->arch->thread()), + frame->append(field)); } else { c->nullaryOp(lir::StoreLoadBarrier); } @@ -5809,7 +5932,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* value = popField(t, frame, fieldCode); unsigned rSize = resultSize(t, fieldCode); - Compiler::OperandType rType = operandTypeForFieldCode(t, fieldCode); + ir::Type rType = operandTypeForFieldCode(t, fieldCode); object pair = makePair(t, context->method, reference); @@ -5821,68 +5944,97 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case FloatField: case IntField: { if (instruction == putstatic) { - c->call - (c->constant - (getThunk(t, setStaticFieldValueFromReferenceThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), rSize, rType, 3, - c->register_(t->arch->thread()), frame->append(pair), - value); + c->call( + c->constant(getThunk(t, setStaticFieldValueFromReferenceThunk), + types.address), + 0, + frame->trace(0, 0), + rSize, + rType, + 3, + c->register_(t->arch->thread()), + frame->append(pair), + value); } else { Compiler::Operand* instance = frame->popObject(); - c->call - (c->constant - (getThunk(t, setFieldValueFromReferenceThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), rSize, rType, 4, - c->register_(t->arch->thread()), frame->append(pair), - instance, value); + c->call(c->constant(getThunk(t, setFieldValueFromReferenceThunk), + types.address), + 0, + frame->trace(0, 0), + rSize, + rType, + 4, + c->register_(t->arch->thread()), + frame->append(pair), + instance, + value); } } break; case DoubleField: case LongField: { if (instruction == putstatic) { - c->call - (c->constant - (getThunk(t, setStaticLongFieldValueFromReferenceThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), rSize, rType, 4, - c->register_(t->arch->thread()), frame->append(pair), - static_cast(0), value); + c->call(c->constant( + getThunk(t, setStaticLongFieldValueFromReferenceThunk), + types.address), + 0, + frame->trace(0, 0), + rSize, + rType, + 4, + c->register_(t->arch->thread()), + frame->append(pair), + static_cast(0), + value); } else { Compiler::Operand* instance = frame->popObject(); - c->call - (c->constant - (getThunk(t, setLongFieldValueFromReferenceThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), rSize, rType, 5, - c->register_(t->arch->thread()), frame->append(pair), - instance, static_cast(0), value); + c->call( + c->constant(getThunk(t, setLongFieldValueFromReferenceThunk), + types.address), + 0, + frame->trace(0, 0), + rSize, + rType, + 5, + c->register_(t->arch->thread()), + frame->append(pair), + instance, + static_cast(0), + value); } } break; case ObjectField: { if (instruction == putstatic) { - c->call - (c->constant - (getThunk(t, setStaticObjectFieldValueFromReferenceThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), rSize, rType, 3, - c->register_(t->arch->thread()), frame->append(pair), - value); + c->call( + c->constant( + getThunk(t, setStaticObjectFieldValueFromReferenceThunk), + types.address), + 0, + frame->trace(0, 0), + rSize, + rType, + 3, + c->register_(t->arch->thread()), + frame->append(pair), + value); } else { Compiler::Operand* instance = frame->popObject(); - c->call - (c->constant - (getThunk(t, setObjectFieldValueFromReferenceThunk), - Compiler::AddressType), - 0, frame->trace(0, 0), rSize, rType, 4, - c->register_(t->arch->thread()), frame->append(pair), - instance, value); + c->call( + c->constant(getThunk(t, setObjectFieldValueFromReferenceThunk), + types.address), + 0, + frame->trace(0, 0), + rSize, + rType, + 4, + c->register_(t->arch->thread()), + frame->append(pair), + instance, + value); } } break; @@ -5906,10 +6058,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, goto next; case sipush: - frame->pushInt - (c->constant - (static_cast(codeReadInt16(t, code, ip)), - Compiler::IntegerType)); + frame->pushInt(c->constant( + static_cast(codeReadInt16(t, code, ip)), types.i4)); break; case swap: @@ -5947,9 +6097,12 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, assert(t, start); Compiler::Operand* key = frame->popInt(); - - c->condJump(lir::JumpIfLess, 4, c->constant(bottom, Compiler::IntegerType), key, - frame->machineIp(defaultIp)); + + c->condJump(lir::JumpIfLess, + 4, + c->constant(bottom, types.i4), + key, + frame->machineIp(defaultIp)); c->save(types.i4, key); @@ -5974,12 +6127,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint16_t index = codeReadInt16(t, code, ip); int16_t count = codeReadInt16(t, code, ip); - storeLocal - (context, 1, - c->binaryOp(lir::Add, - 4, c->constant(count, Compiler::IntegerType), - loadLocal(context, 1, index)), - index); + storeLocal(context, + 1, + c->binaryOp(lir::Add, + 4, + c->constant(count, types.i4), + loadLocal(context, 1, index)), + index); } break; case iload: { @@ -6035,8 +6189,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->restoreState(s->state); - c->condJump(lir::JumpIfGreater, 4, c->constant(s->top, Compiler::IntegerType), s->key, - frame->machineIp(s->defaultIp)); + c->condJump(lir::JumpIfGreater, + 4, + c->constant(s->top, types.i4), + s->key, + frame->machineIp(s->defaultIp)); c->save(types.i4, s->key); ip = s->defaultIp; @@ -6052,23 +6209,29 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->restoreState(s->state); Compiler::Operand* normalizedKey - = (s->bottom - ? c->binaryOp(lir::Subtract, 4, c->constant(s->bottom, Compiler::IntegerType), s->key) - : s->key); + = (s->bottom + ? c->binaryOp( + lir::Subtract, 4, c->constant(s->bottom, types.i4), s->key) + : s->key); - Compiler::Operand* entry = c->memory - (frame->absoluteAddressOperand(s->start), Compiler::AddressType, 0, - normalizedKey, TargetBytesPerWord); + Compiler::Operand* entry + = c->memory(frame->absoluteAddressOperand(s->start), + types.address, + 0, + normalizedKey, + TargetBytesPerWord); - c->jmp - (c->load - (TargetBytesPerWord, TargetBytesPerWord, context->bootContext - ? c->binaryOp(lir::Add, - TargetBytesPerWord, c->memory - (c->register_(t->arch->thread()), Compiler::AddressType, - TARGET_THREAD_CODEIMAGE), entry) - : entry, - TargetBytesPerWord)); + c->jmp(c->load(TargetBytesPerWord, + TargetBytesPerWord, + context->bootContext + ? c->binaryOp(lir::Add, + TargetBytesPerWord, + c->memory(c->register_(t->arch->thread()), + types.address, + TARGET_THREAD_CODEIMAGE), + entry) + : entry, + TargetBytesPerWord)); s->state = c->saveState(); } goto switchloop; From 6ed7681dc0627a7d87a8cea44c0b4ac5a792f1d6 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 22:02:57 -0600 Subject: [PATCH 10/89] use ir::Type in f2i and friends, instead of aSize --- include/avian/codegen/compiler.h | 6 +++--- src/codegen/compiler.cpp | 20 ++++++++++++++------ src/compile.cpp | 24 ++++++++++++------------ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index c8375f49c6..c38636161d 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -127,9 +127,9 @@ class Compiler { virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) = 0; virtual void nullaryOp(lir::Operation type) = 0; - virtual Operand* f2f(unsigned aSize, ir::Type resType, Operand* a) = 0; - virtual Operand* f2i(unsigned aSize, ir::Type resType, Operand* a) = 0; - virtual Operand* i2f(unsigned aSize, ir::Type resType, Operand* a) = 0; + virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) = 0; + virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) = 0; + virtual Operand* i2f(ir::Type aType, ir::Type resType, Operand* a) = 0; virtual void compile(uintptr_t stackOverflowHandler, unsigned stackLimitOffset) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 496f29e2a3..d298b24c70 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2649,42 +2649,50 @@ class MyCompiler: public Compiler { return result; } - virtual Operand* f2f(unsigned aSize, ir::Type resType, Operand* a) + virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) { + assert(&c, aType == static_cast(a)->type); assert(&c, isFloatValue(a)); assert(&c, resType.flavor() == ir::Type::Float); + assert(&c, aType.flavor() == ir::Type::Float); Value* result = value(&c, resType); appendTranslate(&c, lir::Float2Float, - aSize, + aType.size(), static_cast(a), resType.size(), result); return result; } - virtual Operand* f2i(unsigned aSize, ir::Type resType, Operand* a) + virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) { + // TODO: enable when possible + // assert(&c, aType == static_cast(a)->type); assert(&c, isFloatValue(a)); assert(&c, resType.flavor() != ir::Type::Float); + assert(&c, aType.flavor() == ir::Type::Float); Value* result = value(&c, resType); appendTranslate(&c, lir::Float2Int, - aSize, + aType.size(), static_cast(a), resType.size(), result); return result; } - virtual Operand* i2f(unsigned aSize, ir::Type resType, Operand* a) + virtual Operand* i2f(ir::Type aType, ir::Type resType, Operand* a) { + // TODO: enable when possible + // assert(&c, aType == static_cast(a)->type); assert(&c, isGeneralValue(a)); assert(&c, resType.flavor() == ir::Type::Float); + assert(&c, aType.flavor() != ir::Type::Float); Value* result = value(&c, resType); appendTranslate(&c, lir::Int2Float, - aSize, + aType.size(), static_cast(a), resType.size(), result); diff --git a/src/compile.cpp b/src/compile.cpp index 360be4a5ba..5cc52c3f56 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4417,15 +4417,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case d2f: { - frame->pushInt(c->f2f(8, types.f4, frame->popLong())); + frame->pushInt(c->f2f(types.f8, types.f4, frame->popLong())); } break; case d2i: { - frame->pushInt(c->f2i(8, types.i4, frame->popLong())); + frame->pushInt(c->f2i(types.f8, types.i4, frame->popLong())); } break; case d2l: { - frame->pushLong(c->f2i(8, types.i8, frame->popLong())); + frame->pushLong(c->f2i(types.f8, types.i8, frame->popLong())); } break; case dadd: @@ -4518,15 +4518,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case f2d: { - frame->pushLong(c->f2f(4, types.f8, frame->popInt())); + frame->pushLong(c->f2f(types.f4, types.f8, frame->popInt())); } break; case f2i: { - frame->pushInt(c->f2i(4, types.i4, frame->popInt())); + frame->pushInt(c->f2i(types.f4, types.i4, frame->popInt())); } break; case f2l: { - frame->pushLong(c->f2i(4, types.i8, frame->popInt())); + frame->pushLong(c->f2i(types.f4, types.i8, frame->popInt())); } break; case fadd: @@ -4706,7 +4706,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 8, 8, c->memory( - table, types.f4, targetFieldOffset(context, field), 0, 1), + table, types.f8, targetFieldOffset(context, field), 0, 1), 8)); break; @@ -4715,7 +4715,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 8, 8, c->memory( - table, types.i4, targetFieldOffset(context, field), 0, 1), + table, types.i8, targetFieldOffset(context, field), 0, 1), 8)); break; @@ -4828,11 +4828,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2d: { - frame->pushLong(c->i2f(4, types.f8, frame->popInt())); + frame->pushLong(c->i2f(types.i4, types.f8, frame->popInt())); } break; case i2f: { - frame->pushInt(c->i2f(4, types.f4, frame->popInt())); + frame->pushInt(c->i2f(types.i4, types.f4, frame->popInt())); } break; case i2l: @@ -5331,11 +5331,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto start; case l2d: { - frame->pushLong(c->i2f(8, types.f8, frame->popLong())); + frame->pushLong(c->i2f(types.i8, types.f8, frame->popLong())); } break; case l2f: { - frame->pushInt(c->i2f(8, types.f4, frame->popLong())); + frame->pushInt(c->i2f(types.i8, types.f4, frame->popLong())); } break; case l2i: From 2d444830d0ce8ecfc9c18dbca4cfbd6c02e07fe2 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 22:11:49 -0600 Subject: [PATCH 11/89] use ir::Type in Compiler::unaryOp and Compiler::binaryOp --- include/avian/codegen/compiler.h | 17 ++++-- src/codegen/compiler.cpp | 91 ++++++++++++++++++++++---------- src/compile.cpp | 68 +++++++++++++----------- 3 files changed, 114 insertions(+), 62 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index c38636161d..28502e3dfd 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -117,15 +117,22 @@ class Compiler { virtual Operand* loadz(unsigned size, unsigned srcSelectSize, Operand* src, unsigned dstSize) = 0; - - virtual void condJump(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b, Operand* address) = 0; + virtual void condJump(lir::TernaryOperation op, + unsigned size, + Operand* a, + Operand* b, + Operand* address) = 0; virtual void jmp(Operand* address) = 0; virtual void exit(Operand* address) = 0; - virtual Operand* binaryOp(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b) = 0; - virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) = 0; - virtual void nullaryOp(lir::Operation type) = 0; + virtual Operand* binaryOp(lir::TernaryOperation op, + ir::Type type, + Operand* a, + Operand* b) = 0; + virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a) + = 0; + virtual void nullaryOp(lir::Operation op) = 0; virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) = 0; virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index d298b24c70..0fbb0dc142 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -735,10 +735,14 @@ saveLocals(Context* c, Event* e) } } -void -maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, - unsigned srcSelectSize, Value* srcValue, unsigned dstSize, Value* dstValue, - const SiteMask& dstMask) +void maybeMove(Context* c, + lir::BinaryOperation op, + unsigned srcSize, + unsigned srcSelectSize, + Value* srcValue, + unsigned dstSize, + Value* dstValue, + const SiteMask& dstMask) { Read* read = live(c, dstValue); bool isStore = read == 0; @@ -790,8 +794,14 @@ maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, srcValue->source->freeze(c, srcValue); - apply(c, type, min(srcSelectSize, dstSize), srcValue->source, srcValue->source, - dstSize, target, target); + apply(c, + op, + min(srcSelectSize, dstSize), + srcValue->source, + srcValue->source, + dstSize, + target, + target); srcValue->source->thaw(c, srcValue); } else { @@ -803,7 +813,7 @@ maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, bool thunk; OperandMask src; - c->arch->planSource(type, dstSize, src, dstSize, &thunk); + c->arch->planSource(op, dstSize, src, dstSize, &thunk); if (isGeneralValue(srcValue)) { src.registerMask &= c->regFile->generalRegisters.mask; @@ -828,8 +838,14 @@ maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, srcb, dstb, srcValue, dstValue); } - apply(c, type, srcSelectSize, srcValue->source, srcValue->source, - dstSize, tmpTarget, tmpTarget); + apply(c, + op, + srcSelectSize, + srcValue->source, + srcValue->source, + dstSize, + tmpTarget, + tmpTarget); tmpTarget->thaw(c, dstValue); @@ -2610,15 +2626,22 @@ class MyCompiler: public Compiler { return dst; } - virtual void condJump(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b, - Operand* address) + virtual void condJump(lir::TernaryOperation op, + unsigned size, + Operand* a, + Operand* b, + Operand* address) { assert(&c, - (isGeneralBranch(type) and isGeneralValue(a) and isGeneralValue(b)) - or (isFloatBranch(type) and isFloatValue(a) and isFloatValue(b))); + (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or( + isFloatBranch(op) and isFloatValue(a) and isFloatValue(b))); - appendBranch(&c, type, size, static_cast(a), - static_cast(b), static_cast(address)); + appendBranch(&c, + op, + size, + static_cast(a), + static_cast(b), + static_cast(address)); } virtual void jmp(Operand* address) { @@ -2629,23 +2652,36 @@ class MyCompiler: public Compiler { appendJump(&c, lir::Jump, static_cast(address), true); } - virtual Operand* binaryOp(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b) { + virtual Operand* binaryOp(lir::TernaryOperation op, + ir::Type type, + Operand* a, + Operand* b) + { assert(&c, - (isGeneralBinaryOp(type) and isGeneralValue(a) and isGeneralValue(b)) - or (isFloatBinaryOp(type) and isFloatValue(a) and isFloatValue(b))); + (isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b)) + or(isFloatBinaryOp(op) and isFloatValue(a) and isFloatValue(b))); Value* result = value(&c, static_cast(a)->type); - - appendCombine(&c, type, size, static_cast(a), - size, static_cast(b), size, result); + + appendCombine(&c, + op, + type.size(), + static_cast(a), + type.size(), + static_cast(b), + type.size(), + result); return result; } - virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) { - assert(&c, (isGeneralUnaryOp(type) and isGeneralValue(a))or( - isFloatUnaryOp(type) and isFloatValue(a))); + virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a) + { + assert(&c, + (isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op) + and isFloatValue(a))); Value* result = value(&c, static_cast(a)->type); - appendTranslate(&c, type, size, static_cast(a), size, result); + appendTranslate( + &c, op, type.size(), static_cast(a), type.size(), result); return result; } @@ -2699,8 +2735,9 @@ class MyCompiler: public Compiler { return result; } - virtual void nullaryOp(lir::Operation type) { - appendOperation(&c, type); + virtual void nullaryOp(lir::Operation op) + { + appendOperation(&c, op); } virtual void compile(uintptr_t stackOverflowHandler, diff --git a/src/compile.cpp b/src/compile.cpp index 5cc52c3f56..e5b64670b4 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1411,7 +1411,7 @@ class Frame { bc->constants = makeTriple(t, o, pointer, bc->constants); return c->binaryOp(lir::Add, - TargetBytesPerWord, + types.address, c->memory(c->register_(t->arch->thread()), types.address, TARGET_THREAD_HEAPIMAGE), @@ -1643,7 +1643,7 @@ class Frame { return context->bootContext ? c->binaryOp( lir::Add, - TargetBytesPerWord, + types.address, c->memory(c->register_(t->arch->thread()), types.address, TARGET_THREAD_CODEIMAGE), @@ -3732,17 +3732,19 @@ intrinsic(MyThread* t, Frame* frame, object target) if (MATCH(methodName(t, target), "sqrt") and MATCH(methodSpec(t, target), "(D)D")) { - frame->pushLong(c->unaryOp(lir::FloatSquareRoot, 8, frame->popLong())); + frame->pushLong( + c->unaryOp(lir::FloatSquareRoot, types.f8, frame->popLong())); return true; } else if (MATCH(methodName(t, target), "abs")) { if (MATCH(methodSpec(t, target), "(I)I")) { - frame->pushInt(c->unaryOp(lir::Absolute, 4, frame->popInt())); + frame->pushInt(c->unaryOp(lir::Absolute, types.i4, frame->popInt())); return true; } else if (MATCH(methodSpec(t, target), "(J)J")) { - frame->pushLong(c->unaryOp(lir::Absolute, 8, frame->popLong())); + frame->pushLong(c->unaryOp(lir::Absolute, types.i8, frame->popLong())); return true; } else if (MATCH(methodSpec(t, target), "(F)F")) { - frame->pushInt(c->unaryOp(lir::FloatAbsolute, 4, frame->popInt())); + frame->pushInt( + c->unaryOp(lir::FloatAbsolute, types.f4, frame->popInt())); return true; } } @@ -4224,10 +4226,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, array, c->binaryOp( lir::Add, - 4, + types.i4, c->constant(TargetArrayBody, types.i4), c->binaryOp(lir::ShiftLeft, - 4, + types.i4, c->constant(log(TargetBytesPerWord), types.i4), index)), value); @@ -4436,7 +4438,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popLong(); Compiler::Operand* b = frame->popLong(); - frame->pushLong(c->binaryOp(toCompilerBinaryOp(t, instruction), 8, a, b)); + frame->pushLong( + c->binaryOp(toCompilerBinaryOp(t, instruction), types.f8, a, b)); } break; case dcmpg: { @@ -4490,7 +4493,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case dneg: { - frame->pushLong(c->unaryOp(lir::FloatNegate, 8, frame->popLong())); + frame->pushLong(c->unaryOp(lir::FloatNegate, types.f8, frame->popLong())); } break; case dup: @@ -4537,7 +4540,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popInt(); Compiler::Operand* b = frame->popInt(); - frame->pushInt(c->binaryOp(toCompilerBinaryOp(t, instruction), 4, a, b)); + frame->pushInt( + c->binaryOp(toCompilerBinaryOp(t, instruction), types.f4, a, b)); } break; case fcmpg: { @@ -4591,7 +4595,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case fneg: { - frame->pushInt(c->unaryOp(lir::FloatNegate, 4, frame->popInt())); + frame->pushInt(c->unaryOp(lir::FloatNegate, types.f4, frame->popInt())); } break; case getfield: @@ -4855,7 +4859,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case imul: { Compiler::Operand* a = frame->popInt(); Compiler::Operand* b = frame->popInt(); - frame->pushInt(c->binaryOp(toCompilerBinaryOp(t, instruction), 4, a, b)); + frame->pushInt( + c->binaryOp(toCompilerBinaryOp(t, instruction), types.i4, a, b)); } break; case iconst_m1: @@ -4895,7 +4900,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->trace(0, 0); } - frame->pushInt(c->binaryOp(lir::Divide, 4, a, b)); + frame->pushInt(c->binaryOp(lir::Divide, types.i4, a, b)); } break; case if_acmpeq: @@ -4982,7 +4987,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, storeLocal(context, 1, c->binaryOp(lir::Add, - 4, + types.i4, c->constant(count, types.i4), loadLocal(context, 1, index)), index); @@ -5014,7 +5019,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case ineg: { - frame->pushInt(c->unaryOp(lir::Negate, 4, frame->popInt())); + frame->pushInt(c->unaryOp(lir::Negate, types.i4, frame->popInt())); } break; case instanceof: { @@ -5203,7 +5208,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* result = c->stackCall( c->memory( c->binaryOp(lir::And, - TargetBytesPerWord, + types.address, c->constant(TargetPointerMask, types.i4), c->memory(instance, types.object, 0, 0, 1)), types.object, @@ -5265,7 +5270,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->trace(0, 0); } - frame->pushInt(c->binaryOp(lir::Remainder, 4, a, b)); + frame->pushInt(c->binaryOp(lir::Remainder, types.i4, a, b)); } break; case ireturn: { @@ -5350,7 +5355,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lmul: { Compiler::Operand* a = frame->popLong(); Compiler::Operand* b = frame->popLong(); - frame->pushLong(c->binaryOp(toCompilerBinaryOp(t, instruction), 8, a, b)); + frame->pushLong( + c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b)); } break; case lcmp: { @@ -5464,7 +5470,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->trace(0, 0); } - frame->pushLong(c->binaryOp(lir::Divide, 8, a, b)); + frame->pushLong(c->binaryOp(lir::Divide, types.i8, a, b)); } break; case lload: @@ -5493,7 +5499,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case lneg: - frame->pushLong(c->unaryOp(lir::Negate, 8, frame->popLong())); + frame->pushLong(c->unaryOp(lir::Negate, types.i8, frame->popLong())); break; case lookupswitch: { @@ -5546,7 +5552,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->jmp(context->bootContext ? c->binaryOp(lir::Add, - TargetBytesPerWord, + types.address, c->memory(c->register_(t->arch->thread()), types.address, TARGET_THREAD_CODEIMAGE), @@ -5573,7 +5579,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->trace(0, 0); } - frame->pushLong(c->binaryOp(lir::Remainder, 8, a, b)); + frame->pushLong(c->binaryOp(lir::Remainder, types.i8, a, b)); } break; case lreturn: { @@ -5592,7 +5598,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lushr: { Compiler::Operand* a = frame->popInt(); Compiler::Operand* b = frame->popLong(); - frame->pushLong(c->binaryOp(toCompilerBinaryOp(t, instruction), 8, a, b)); + frame->pushLong( + c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b)); } break; case lstore: @@ -6130,7 +6137,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, storeLocal(context, 1, c->binaryOp(lir::Add, - 4, + types.i4, c->constant(count, types.i4), loadLocal(context, 1, index)), index); @@ -6209,10 +6216,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->restoreState(s->state); Compiler::Operand* normalizedKey - = (s->bottom - ? c->binaryOp( - lir::Subtract, 4, c->constant(s->bottom, types.i4), s->key) - : s->key); + = (s->bottom ? c->binaryOp(lir::Subtract, + types.i4, + c->constant(s->bottom, types.i4), + s->key) + : s->key); Compiler::Operand* entry = c->memory(frame->absoluteAddressOperand(s->start), @@ -6225,7 +6233,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TargetBytesPerWord, context->bootContext ? c->binaryOp(lir::Add, - TargetBytesPerWord, + types.address, c->memory(c->register_(t->arch->thread()), types.address, TARGET_THREAD_CODEIMAGE), From 8af9bb82972dd65515a9043a59f7b2ecb7f3ba34 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 22:27:19 -0600 Subject: [PATCH 12/89] change Compiler::register_ to Compiler::threadRegister, since it was only used as such --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 24 ++++---- src/codegen/compiler/event.cpp | 66 +++++++++++++------- src/codegen/compiler/value.cpp | 10 ---- src/codegen/compiler/value.h | 1 - src/compile.cpp | 100 +++++++++++++++---------------- 6 files changed, 107 insertions(+), 96 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 28502e3dfd..c3ab903d8e 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -72,7 +72,7 @@ class Compiler { Operand* index = 0, unsigned scale = 1) = 0; - virtual Operand* register_(int number) = 0; + virtual Operand* threadRegister() = 0; virtual void push(ir::Type type, Operand* value) = 0; virtual void save(ir::Type type, Operand* value) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 0fbb0dc142..9c7879a192 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -1237,17 +1237,10 @@ loadLocal(Context* c, unsigned footprint, unsigned index) return c->locals[index].value; } -Value* -register_(Context* c, int number) +Value* threadRegister(Context* c) { - assert(c, (1 << number) & (c->regFile->generalRegisters.mask - | c->regFile->floatRegisters.mask)); - - Site* s = registerSite(c, number); - lir::ValueType type = ((1 << number) & c->regFile->floatRegisters.mask) - ? lir::ValueFloat: lir::ValueGeneral; - - return value(c, type, s, s); + Site* s = registerSite(c, c->arch->thread()); + return value(c, ir::Type(ir::Type::Address, TargetBytesPerWord), s, s); } unsigned @@ -2319,7 +2312,9 @@ class MyCompiler: public Compiler { } virtual Operand* address(Promise* address) { - return value(&c, lir::ValueGeneral, compiler::addressSite(&c, address)); + return value(&c, + ir::Type(ir::Type::Address, TargetBytesPerWord), + compiler::addressSite(&c, address)); } virtual Operand* memory(Operand* base, @@ -2336,8 +2331,9 @@ class MyCompiler: public Compiler { return result; } - virtual Operand* register_(int number) { - return compiler::register_(&c, number); + virtual Operand* threadRegister() + { + return compiler::threadRegister(&c); } Promise* machineIp() { @@ -2378,7 +2374,7 @@ class MyCompiler: public Compiler { } virtual void pushed() { - Value* v = value(&c, lir::ValueGeneral); + Value* v = value(&c, ir::Type(ir::Type::Object, TargetBytesPerWord)); appendFrameSite (&c, v, frameIndex (&c, (c.stack ? c.stack->index : 0) + c.localFootprint)); diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 51eaff85c7..ab6e8d2563 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -82,8 +82,7 @@ Site* pickTargetSite(Context* c, Read* read, bool intersectRead = false, unsigned registerReserveCount = 0, CostCalculator* costCalculator = 0); -Value* -register_(Context* c, int number); +Value* threadRegister(Context* c); Event::Event(Context* c): next(0), stackBefore(c->stack), localsBefore(c->locals), @@ -929,15 +928,23 @@ appendCombine(Context* c, lir::TernaryOperation type, if (threadParameter) { ++ stackSize; - compiler::push(c, 1, register_(c, c->arch->thread())); + compiler::push(c, 1, threadRegister(c)); } Stack* argumentStack = c->stack; c->stack = oldStack; - appendCall - (c, value(c, lir::ValueGeneral, constantSite(c, handler)), 0, 0, resultValue, - resultSize, argumentStack, stackSize, 0); + appendCall(c, + value(c, + ir::Type(ir::Type::Address, vm::TargetBytesPerWord), + constantSite(c, handler)), + 0, + 0, + resultValue, + resultSize, + argumentStack, + stackSize, + 0); } else { append (c, new(c->zone) @@ -1049,12 +1056,18 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, Stack* argumentStack = c->stack; c->stack = oldStack; - appendCall - (c, value - (c, lir::ValueGeneral, constantSite - (c, c->client->getThunk(type, firstSize, resultSize))), - 0, 0, resultValue, resultSize, argumentStack, - ceilingDivide(firstSize, vm::TargetBytesPerWord), 0); + appendCall(c, + value(c, + ir::Type(ir::Type::Address, vm::TargetBytesPerWord), + constantSite( + c, c->client->getThunk(type, firstSize, resultSize))), + 0, + 0, + resultValue, + resultSize, + argumentStack, + ceilingDivide(firstSize, vm::TargetBytesPerWord), + 0); } else { append(c, new(c->zone) TranslateEvent @@ -1407,15 +1420,28 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first Stack* argumentStack = c->stack; c->stack = oldStack; - Value* result = value(c, lir::ValueGeneral); - appendCall - (c, value - (c, lir::ValueGeneral, constantSite(c, handler)), 0, 0, result, 4, - argumentStack, ceilingDivide(size, vm::TargetBytesPerWord) * 2, 0); + Value* result + = value(c, ir::Type(ir::Type::Address, vm::TargetBytesPerWord)); + appendCall(c, + value(c, + ir::Type(ir::Type::Address, vm::TargetBytesPerWord), + constantSite(c, handler)), + 0, + 0, + result, + 4, + argumentStack, + ceilingDivide(size, vm::TargetBytesPerWord) * 2, + 0); - appendBranch(c, thunkBranch(c, type), 4, value - (c, lir::ValueGeneral, constantSite(c, static_cast(0))), - result, addressValue); + appendBranch(c, + thunkBranch(c, type), + 4, + value(c, + ir::Type(ir::Type::Address, vm::TargetBytesPerWord), + constantSite(c, static_cast(0))), + result, + addressValue); } else { append (c, new(c->zone) diff --git a/src/codegen/compiler/value.cpp b/src/codegen/compiler/value.cpp index 12a9ef6b5c..3fdccf23d6 100644 --- a/src/codegen/compiler/value.cpp +++ b/src/codegen/compiler/value.cpp @@ -162,16 +162,6 @@ bool Value::hasBuddy(Context* c, Value* b) { } #endif // not NDEBUG - -Value* value(Context* c, lir::ValueType type, Site* site, Site* target) { - return value( - c, - ir::Type(type == lir::ValueGeneral ? ir::Type::Integer : ir::Type::Float, - vm::TargetBytesPerWord), - site, - target); -} - Value* value(Context* c, ir::Type type, Site* site, Site* target) { return new(c->zone) Value(site, target, type); diff --git a/src/codegen/compiler/value.h b/src/codegen/compiler/value.h index 8db231639e..623042ce83 100644 --- a/src/codegen/compiler/value.h +++ b/src/codegen/compiler/value.h @@ -77,7 +77,6 @@ inline bool isGeneralValue(Compiler::Operand* a) return !isFloatValue(a); } -Value* value(Context* c, lir::ValueType type, Site* site = 0, Site* target = 0); Value* value(Context* c, ir::Type type, Site* site = 0, Site* target = 0); } // namespace compiler diff --git a/src/compile.cpp b/src/compile.cpp index e5b64670b4..b0a42cadd2 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1410,12 +1410,12 @@ class Frame { object pointer = makePointer(t, p); bc->constants = makeTriple(t, o, pointer, bc->constants); - return c->binaryOp(lir::Add, - types.address, - c->memory(c->register_(t->arch->thread()), - types.address, - TARGET_THREAD_HEAPIMAGE), - c->promiseConstant(p, types.address)); + return c->binaryOp( + lir::Add, + types.address, + c->memory( + c->threadRegister(), types.address, TARGET_THREAD_HEAPIMAGE), + c->promiseConstant(p, types.address)); } else { for (PoolElement* e = context->objectPool; e; e = e->next) { if (o == e->target) { @@ -1644,7 +1644,7 @@ class Frame { ? c->binaryOp( lir::Add, types.address, - c->memory(c->register_(t->arch->thread()), + c->memory(c->threadRegister(), types.address, TARGET_THREAD_CODEIMAGE), c->promiseConstant( @@ -3160,7 +3160,7 @@ void compileSafePoint(MyThread* t, Compiler* c, Frame* frame) { 0, types.void_, 1, - c->register_(t->arch->thread())); + c->threadRegister()); } Compiler::Operand* @@ -3204,12 +3204,12 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall, operandTypeForFieldCode(t, methodReturnCode(t, target)), methodParameterFootprint(t, target)); - c->store(TargetBytesPerWord, - frame->absoluteAddressOperand(returnAddressPromise), - TargetBytesPerWord, - c->memory(c->register_(t->arch->thread()), - types.address, - TARGET_THREAD_TAILADDRESS)); + c->store( + TargetBytesPerWord, + frame->absoluteAddressOperand(returnAddressPromise), + TargetBytesPerWord, + c->memory( + c->threadRegister(), types.address, TARGET_THREAD_TAILADDRESS)); c->exit(c->constant((methodFlags(t, target) & ACC_NATIVE) ? nativeThunk(t) @@ -3363,7 +3363,7 @@ compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk, TargetBytesPerWord, types.address, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(pair)), reference, isStatic, @@ -3411,7 +3411,7 @@ compileDirectAbstractInvoke(MyThread* t, Frame* frame, Thunk thunk, TargetBytesPerWord, types.address, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(target)), target, tailCall); @@ -3440,7 +3440,7 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) 0, types.void_, 2, - c->register_(t->arch->thread()), + c->threadRegister(), lock); } } @@ -4093,7 +4093,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 1, - c->register_(t->arch->thread())); + c->threadRegister()); } // fprintf(stderr, "ip: %d map: %ld\n", ip, *(frame->map)); @@ -4222,7 +4222,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 4, - c->register_(t->arch->thread()), + c->threadRegister(), array, c->binaryOp( lir::Add, @@ -4328,7 +4328,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TargetBytesPerWord, types.object, 3, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(argument), length)); } break; @@ -4374,7 +4374,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 2, - c->register_(t->arch->thread()), + c->threadRegister(), target); c->nullaryOp(lir::Trap); @@ -4413,7 +4413,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 3, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(argument), instance); } break; @@ -4624,7 +4624,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(field)); } @@ -4642,7 +4642,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(fieldClass(t, field))); } @@ -4748,7 +4748,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(field)); } else { c->nullaryOp(lir::LoadBarrier); @@ -4773,7 +4773,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, rSize, rType, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(pair)); } else { Compiler::Operand* instance = frame->popObject(); @@ -4786,7 +4786,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, rSize, rType, 3, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(pair), instance); } @@ -5050,7 +5050,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 4, types.i4, 3, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(argument), instance)); } break; @@ -5100,7 +5100,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TargetBytesPerWord, types.address, 3, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(argument), c->peek(1, parameterFootprint - 1)), tailCall ? Compiler::TailJump : 0, @@ -5250,7 +5250,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TargetBytesPerWord, types.address, 3, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(pair), c->peek(1, methodReferenceParameterFootprint(t, reference, false) @@ -5420,7 +5420,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TargetBytesPerWord, types.object, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(makePair(t, context->method, reference)))); } } @@ -5434,7 +5434,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TargetBytesPerWord, types.object, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(v))); } else { frame->pushObject(frame->append(v)); @@ -5553,7 +5553,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->jmp(context->bootContext ? c->binaryOp(lir::Add, types.address, - c->memory(c->register_(t->arch->thread()), + c->memory(c->threadRegister(), types.address, TARGET_THREAD_CODEIMAGE), address) @@ -5636,7 +5636,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 2, - c->register_(t->arch->thread()), + c->threadRegister(), target); } break; @@ -5649,7 +5649,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 2, - c->register_(t->arch->thread()), + c->threadRegister(), target); } break; @@ -5686,7 +5686,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TargetBytesPerWord, types.object, 4, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(argument), c->constant(dimensions, types.i4), c->constant(offset, types.i4)); @@ -5725,7 +5725,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TargetBytesPerWord, types.object, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(argument))); } break; @@ -5741,7 +5741,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TargetBytesPerWord, types.object, 3, - c->register_(t->arch->thread()), + c->threadRegister(), c->constant(type, types.i4), length)); } break; @@ -5784,7 +5784,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(fieldClass(t, field))); } @@ -5811,7 +5811,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(field)); } else { c->nullaryOp(lir::StoreStoreBarrier); @@ -5895,7 +5895,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 4, - c->register_(t->arch->thread()), + c->threadRegister(), table, c->constant(targetFieldOffset(context, field), types.i4), value); @@ -5906,7 +5906,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 4, - c->register_(t->arch->thread()), + c->threadRegister(), table, c->constant(targetFieldOffset(context, field), types.i4), value); @@ -5927,7 +5927,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.void_, 2, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(field)); } else { c->nullaryOp(lir::StoreLoadBarrier); @@ -5959,7 +5959,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, rSize, rType, 3, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(pair), value); } else { @@ -5972,7 +5972,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, rSize, rType, 4, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(pair), instance, value); @@ -5990,7 +5990,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, rSize, rType, 4, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(pair), static_cast(0), value); @@ -6005,7 +6005,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, rSize, rType, 5, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(pair), instance, static_cast(0), @@ -6024,7 +6024,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, rSize, rType, 3, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(pair), value); } else { @@ -6038,7 +6038,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, rSize, rType, 4, - c->register_(t->arch->thread()), + c->threadRegister(), frame->append(pair), instance, value); @@ -6234,7 +6234,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, context->bootContext ? c->binaryOp(lir::Add, types.address, - c->memory(c->register_(t->arch->thread()), + c->memory(c->threadRegister(), types.address, TARGET_THREAD_CODEIMAGE), entry) From 2ed52c05a80ccfe1fa92b0aa60c5ac025abbae9b Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 22:33:54 -0600 Subject: [PATCH 13/89] use ir::Type in Compiler::store --- include/avian/codegen/compiler.h | 4 +- src/codegen/compiler.cpp | 13 ++++-- src/compile.cpp | 80 ++++++++++++++++++-------------- 3 files changed, 57 insertions(+), 40 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index c3ab903d8e..d6c75ad382 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -110,7 +110,9 @@ class Compiler { virtual void checkBounds(Operand* object, unsigned lengthOffset, Operand* index, intptr_t handler) = 0; - virtual void store(unsigned srcSize, Operand* src, unsigned dstSize, + virtual void store(ir::Type srcType, + Operand* src, + ir::Type dstType, Operand* dst) = 0; virtual Operand* load(unsigned srcSize, unsigned srcSelectSize, Operand* src, unsigned dstSize) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 9c7879a192..1e15fedfce 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2593,11 +2593,18 @@ class MyCompiler: public Compiler { static_cast(index), handler); } - virtual void store(unsigned srcSize, Operand* src, unsigned dstSize, + virtual void store(ir::Type srcType, + Operand* src, + ir::Type dstType, Operand* dst) { - appendMove(&c, lir::Move, srcSize, srcSize, static_cast(src), - dstSize, static_cast(dst)); + appendMove(&c, + lir::Move, + srcType.size(), + srcType.size(), + static_cast(src), + dstType.size(), + static_cast(dst)); } virtual Operand* load(unsigned srcSize, unsigned srcSelectSize, Operand* src, diff --git a/src/compile.cpp b/src/compile.cpp index b0a42cadd2..e65769b097 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3205,9 +3205,9 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall, methodParameterFootprint(t, target)); c->store( - TargetBytesPerWord, + types.address, frame->absoluteAddressOperand(returnAddressPromise), - TargetBytesPerWord, + types.address, c->memory( c->threadRegister(), types.address, TARGET_THREAD_TAILADDRESS)); @@ -3764,8 +3764,10 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store( - TargetBytesPerWord, value, 1, c->memory(address, types.i4, 0, 0, 1)); + c->store(types.address, + value, + types.i1, + c->memory(address, types.i4, 0, 0, 1)); return true; } else if ((MATCH(methodName(t, target), "getShort") and MATCH(methodSpec(t, target), "(J)S")) @@ -3785,8 +3787,10 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store( - TargetBytesPerWord, value, 2, c->memory(address, types.i4, 0, 0, 1)); + c->store(types.address, + value, + types.i2, + c->memory(address, types.i4, 0, 0, 1)); return true; } else if ((MATCH(methodName(t, target), "getInt") and MATCH(methodSpec(t, target), "(J)I")) @@ -3814,9 +3818,9 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(TargetBytesPerWord, + c->store(types.address, value, - 4, + types.i4, c->memory( address, MATCH(methodName(t, target), "putInt") ? types.i4 : types.f4, @@ -3850,9 +3854,9 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popLong(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(8, + c->store(types.i8, value, - 8, + types.i8, c->memory(address, MATCH(methodName(t, target), "putLong") ? types.i4 : types.f4, @@ -3876,9 +3880,9 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popLong(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(8, + c->store(types.i8, value, - TargetBytesPerWord, + types.address, c->memory(address, types.address, 0, 0, 1)); return true; } @@ -4236,42 +4240,46 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case fastore: - c->store(TargetBytesPerWord, + c->store(types.address, value, - 4, + types.f4, c->memory(array, types.f4, TargetArrayBody, index, 4)); break; case iastore: - c->store(TargetBytesPerWord, + c->store(types.address, value, - 4, + types.f4, c->memory(array, types.i4, TargetArrayBody, index, 4)); break; case bastore: - c->store(TargetBytesPerWord, + c->store(types.address, value, - 1, + types.i1, c->memory(array, types.i4, TargetArrayBody, index, 1)); break; case castore: case sastore: - c->store(TargetBytesPerWord, + c->store(types.address, value, - 2, + types.i2, c->memory(array, types.i4, TargetArrayBody, index, 2)); break; case dastore: - c->store( - 8, value, 8, c->memory(array, types.f4, TargetArrayBody, index, 8)); + c->store(types.f8, + value, + types.f8, + c->memory(array, types.f4, TargetArrayBody, index, 8)); break; case lastore: - c->store( - 8, value, 8, c->memory(array, types.i4, TargetArrayBody, index, 8)); + c->store(types.i8, + value, + types.f8, + c->memory(array, types.i4, TargetArrayBody, index, 8)); break; } } break; @@ -5834,9 +5842,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ByteField: case BooleanField: c->store( - TargetBytesPerWord, + types.address, value, - 1, + types.i1, c->memory( table, types.i4, targetFieldOffset(context, field), 0, 1)); break; @@ -5844,45 +5852,45 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case CharField: case ShortField: c->store( - TargetBytesPerWord, + types.address, value, - 2, + types.i2, c->memory( table, types.i4, targetFieldOffset(context, field), 0, 1)); break; case FloatField: c->store( - TargetBytesPerWord, + types.address, value, - 4, + types.f4, c->memory( table, types.f4, targetFieldOffset(context, field), 0, 1)); break; case IntField: c->store( - TargetBytesPerWord, + types.address, value, - 4, + types.i4, c->memory( table, types.i4, targetFieldOffset(context, field), 0, 1)); break; case DoubleField: c->store( - 8, + types.f8, value, - 8, + types.f8, c->memory( table, types.f4, targetFieldOffset(context, field), 0, 1)); break; case LongField: c->store( - 8, + types.i8, value, - 8, + types.i8, c->memory( table, types.i4, targetFieldOffset(context, field), 0, 1)); break; From aef5acce844b021ecfbb69b1b1d31f7c90fcd3e8 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 22:41:47 -0600 Subject: [PATCH 14/89] add flavor type check to Compiler::store --- src/codegen/compiler.cpp | 2 ++ src/compile.cpp | 28 ++++++++-------------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 1e15fedfce..f8784106bb 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2598,6 +2598,8 @@ class MyCompiler: public Compiler { ir::Type dstType, Operand* dst) { + assert(&c, srcType.flavor() == static_cast(src)->type.flavor()); + // assert(&c, dstType.flavor() == static_cast(dst)->type.flavor()); appendMove(&c, lir::Move, srcType.size(), diff --git a/src/compile.cpp b/src/compile.cpp index e65769b097..f47869e861 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3818,15 +3818,9 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(types.address, - value, - types.i4, - c->memory( - address, - MATCH(methodName(t, target), "putInt") ? types.i4 : types.f4, - 0, - 0, - 1)); + ir::Type type = MATCH(methodName(t, target), "putInt") ? types.i4 + : types.f4; + c->store(type, value, type, c->memory(address, type, 0, 0, 1)); return true; } else if ((MATCH(methodName(t, target), "getLong") and MATCH(methodSpec(t, target), "(J)J")) @@ -3854,15 +3848,9 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popLong(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(types.i8, - value, - types.i8, - c->memory(address, - MATCH(methodName(t, target), "putLong") ? types.i4 - : types.f4, - 0, - 0, - 1)); + ir::Type type = MATCH(methodName(t, target), "putLong") ? types.i8 + : types.f8; + c->store(type, value, type, c->memory(address, type, 0, 0, 1)); return true; } else if (MATCH(methodName(t, target), "getAddress") and MATCH(methodSpec(t, target), "(J)J")) @@ -4240,7 +4228,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case fastore: - c->store(types.address, + c->store(types.f4, value, types.f4, c->memory(array, types.f4, TargetArrayBody, index, 4)); @@ -5861,7 +5849,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case FloatField: c->store( - types.address, + types.f4, value, types.f4, c->memory( From 1fc6011bf7ceb11160b5a61de443f61b6c24393f Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 22:44:51 -0600 Subject: [PATCH 15/89] add extra flavor type check to Compiler::store --- src/codegen/compiler.cpp | 2 +- src/compile.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index f8784106bb..e530610609 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2599,7 +2599,7 @@ class MyCompiler: public Compiler { Operand* dst) { assert(&c, srcType.flavor() == static_cast(src)->type.flavor()); - // assert(&c, dstType.flavor() == static_cast(dst)->type.flavor()); + assert(&c, dstType.flavor() == static_cast(dst)->type.flavor()); appendMove(&c, lir::Move, srcType.size(), diff --git a/src/compile.cpp b/src/compile.cpp index f47869e861..ba013a9008 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4237,7 +4237,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case iastore: c->store(types.address, value, - types.f4, + types.i4, c->memory(array, types.i4, TargetArrayBody, index, 4)); break; @@ -4266,8 +4266,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lastore: c->store(types.i8, value, - types.f8, - c->memory(array, types.i4, TargetArrayBody, index, 8)); + types.i8, + c->memory(array, types.i8, TargetArrayBody, index, 8)); break; } } break; From f9b781149e7cb42a079dda811caa52576209e6b0 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 23:39:44 -0600 Subject: [PATCH 16/89] add extra type checks to Compiler::store and Compiler::memory --- src/codegen/compiler.cpp | 6 ++++++ src/compile.cpp | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index e530610609..016682d8df 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2323,6 +2323,8 @@ class MyCompiler: public Compiler { Operand* index = 0, unsigned scale = 1) { + assert(&c, index != 0 || scale == 1); + assert(&c, type.size() == scale || index == 0); Value* result = value(&c, type); appendMemory(&c, static_cast(base), displacement, @@ -2600,6 +2602,10 @@ class MyCompiler: public Compiler { { assert(&c, srcType.flavor() == static_cast(src)->type.flavor()); assert(&c, dstType.flavor() == static_cast(dst)->type.flavor()); + assert(&c, srcType.flavor() == dstType.flavor()); + assert(&c, + srcType.flavor() != ir::Type::Float + || srcType.size() == static_cast(src)->type.size()); appendMove(&c, lir::Move, srcType.size(), diff --git a/src/compile.cpp b/src/compile.cpp index ba013a9008..cb76f78db0 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4145,7 +4145,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt( c->load(1, 1, - c->memory(array, types.i4, TargetArrayBody, index, 1), + c->memory(array, types.i1, TargetArrayBody, index, 1), TargetBytesPerWord)); break; @@ -4153,25 +4153,25 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt( c->loadz(2, 2, - c->memory(array, types.i4, TargetArrayBody, index, 2), + c->memory(array, types.i2, TargetArrayBody, index, 2), TargetBytesPerWord)); break; case daload: frame->pushLong(c->load( - 8, 8, c->memory(array, types.f4, TargetArrayBody, index, 8), 8)); + 8, 8, c->memory(array, types.f8, TargetArrayBody, index, 8), 8)); break; case laload: frame->pushLong(c->load( - 8, 8, c->memory(array, types.i4, TargetArrayBody, index, 8), 8)); + 8, 8, c->memory(array, types.i8, TargetArrayBody, index, 8), 8)); break; case saload: frame->pushInt( c->load(2, 2, - c->memory(array, types.i4, TargetArrayBody, index, 2), + c->memory(array, types.i2, TargetArrayBody, index, 2), TargetBytesPerWord)); break; } @@ -4245,7 +4245,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store(types.address, value, types.i1, - c->memory(array, types.i4, TargetArrayBody, index, 1)); + c->memory(array, types.i1, TargetArrayBody, index, 1)); break; case castore: @@ -4253,14 +4253,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store(types.address, value, types.i2, - c->memory(array, types.i4, TargetArrayBody, index, 2)); + c->memory(array, types.i2, TargetArrayBody, index, 2)); break; case dastore: c->store(types.f8, value, types.f8, - c->memory(array, types.f4, TargetArrayBody, index, 8)); + c->memory(array, types.f8, TargetArrayBody, index, 8)); break; case lastore: @@ -5453,8 +5453,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, memcpy(&v, &singletonValue(t, pool, index - 1), 8); frame->pushLong(c->constant( v, - singletonBit(t, pool, poolSize(t, pool), index - 1) ? types.f4 - : types.i4)); + singletonBit(t, pool, poolSize(t, pool), index - 1) ? types.f8 + : types.i8)); } break; case ldiv_: { From 9805ff94b4841afe61f3d28a59629f274c3c3c62 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 23:46:26 -0600 Subject: [PATCH 17/89] remove redundant Compiler::memory scale parameter --- include/avian/codegen/compiler.h | 3 +- src/codegen/compiler.cpp | 13 +-- src/compile.cpp | 151 ++++++++++++------------------- 3 files changed, 66 insertions(+), 101 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index d6c75ad382..d09a56dba2 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -69,8 +69,7 @@ class Compiler { virtual Operand* memory(Operand* base, ir::Type type, int displacement = 0, - Operand* index = 0, - unsigned scale = 1) = 0; + Operand* index = 0) = 0; virtual Operand* threadRegister() = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 016682d8df..d5e4a2c5c3 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2320,15 +2320,16 @@ class MyCompiler: public Compiler { virtual Operand* memory(Operand* base, ir::Type type, int displacement = 0, - Operand* index = 0, - unsigned scale = 1) + Operand* index = 0) { - assert(&c, index != 0 || scale == 1); - assert(&c, type.size() == scale || index == 0); Value* result = value(&c, type); - appendMemory(&c, static_cast(base), displacement, - static_cast(index), scale, result); + appendMemory(&c, + static_cast(base), + displacement, + static_cast(index), + index == 0 ? 1 : type.size(), + result); return result; } diff --git a/src/compile.cpp b/src/compile.cpp index cb76f78db0..16dacf6ce3 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3755,8 +3755,8 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushInt(c->load( - 1, 1, c->memory(address, types.i4, 0, 0, 1), TargetBytesPerWord)); + frame->pushInt( + c->load(1, 1, c->memory(address, types.i4), TargetBytesPerWord)); return true; } else if (MATCH(methodName(t, target), "putByte") and MATCH(methodSpec(t, target), "(JB)V")) @@ -3764,10 +3764,7 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(types.address, - value, - types.i1, - c->memory(address, types.i4, 0, 0, 1)); + c->store(types.address, value, types.i1, c->memory(address, types.i4)); return true; } else if ((MATCH(methodName(t, target), "getShort") and MATCH(methodSpec(t, target), "(J)S")) @@ -3776,8 +3773,8 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushInt(c->load( - 2, 2, c->memory(address, types.i4, 0, 0, 1), TargetBytesPerWord)); + frame->pushInt( + c->load(2, 2, c->memory(address, types.i4), TargetBytesPerWord)); return true; } else if ((MATCH(methodName(t, target), "putShort") and MATCH(methodSpec(t, target), "(JS)V")) @@ -3787,10 +3784,7 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(types.address, - value, - types.i2, - c->memory(address, types.i4, 0, 0, 1)); + c->store(types.address, value, types.i2, c->memory(address, types.i4)); return true; } else if ((MATCH(methodName(t, target), "getInt") and MATCH(methodSpec(t, target), "(J)I")) @@ -3804,10 +3798,7 @@ intrinsic(MyThread* t, Frame* frame, object target) 4, c->memory(address, MATCH(methodName(t, target), "getInt") ? types.i4 - : types.f4, - 0, - 0, - 1), + : types.f4), TargetBytesPerWord)); return true; } else if ((MATCH(methodName(t, target), "putInt") @@ -3820,7 +3811,7 @@ intrinsic(MyThread* t, Frame* frame, object target) frame->popObject(); ir::Type type = MATCH(methodName(t, target), "putInt") ? types.i4 : types.f4; - c->store(type, value, type, c->memory(address, type, 0, 0, 1)); + c->store(type, value, type, c->memory(address, type)); return true; } else if ((MATCH(methodName(t, target), "getLong") and MATCH(methodSpec(t, target), "(J)J")) @@ -3834,10 +3825,7 @@ intrinsic(MyThread* t, Frame* frame, object target) 8, c->memory(address, MATCH(methodName(t, target), "getLong") ? types.i4 - : types.f4, - 0, - 0, - 1), + : types.f4), 8)); return true; } else if ((MATCH(methodName(t, target), "putLong") @@ -3850,7 +3838,7 @@ intrinsic(MyThread* t, Frame* frame, object target) frame->popObject(); ir::Type type = MATCH(methodName(t, target), "putLong") ? types.i8 : types.f8; - c->store(type, value, type, c->memory(address, type, 0, 0, 1)); + c->store(type, value, type, c->memory(address, type)); return true; } else if (MATCH(methodName(t, target), "getAddress") and MATCH(methodSpec(t, target), "(J)J")) @@ -3859,7 +3847,7 @@ intrinsic(MyThread* t, Frame* frame, object target) frame->popObject(); frame->pushLong(c->load(TargetBytesPerWord, TargetBytesPerWord, - c->memory(address, types.address, 0, 0, 1), + c->memory(address, types.address), 8)); return true; } else if (MATCH(methodName(t, target), "putAddress") @@ -3868,10 +3856,8 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popLong(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(types.i8, - value, - types.address, - c->memory(address, types.address, 0, 0, 1)); + c->store( + types.i8, value, types.address, c->memory(address, types.address)); return true; } } @@ -4115,21 +4101,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (instruction) { case aaload: - frame->pushObject(c->load(TargetBytesPerWord, - TargetBytesPerWord, - c->memory(array, - types.object, - TargetArrayBody, - index, - TargetBytesPerWord), - TargetBytesPerWord)); + frame->pushObject( + c->load(TargetBytesPerWord, + TargetBytesPerWord, + c->memory(array, types.object, TargetArrayBody, index), + TargetBytesPerWord)); break; case faload: frame->pushInt( c->load(4, 4, - c->memory(array, types.f4, TargetArrayBody, index, 4), + c->memory(array, types.f4, TargetArrayBody, index), TargetBytesPerWord)); break; @@ -4137,7 +4120,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt( c->load(4, 4, - c->memory(array, types.i4, TargetArrayBody, index, 4), + c->memory(array, types.i4, TargetArrayBody, index), TargetBytesPerWord)); break; @@ -4145,7 +4128,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt( c->load(1, 1, - c->memory(array, types.i1, TargetArrayBody, index, 1), + c->memory(array, types.i1, TargetArrayBody, index), TargetBytesPerWord)); break; @@ -4153,25 +4136,25 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt( c->loadz(2, 2, - c->memory(array, types.i2, TargetArrayBody, index, 2), + c->memory(array, types.i2, TargetArrayBody, index), TargetBytesPerWord)); break; case daload: frame->pushLong(c->load( - 8, 8, c->memory(array, types.f8, TargetArrayBody, index, 8), 8)); + 8, 8, c->memory(array, types.f8, TargetArrayBody, index), 8)); break; case laload: frame->pushLong(c->load( - 8, 8, c->memory(array, types.i8, TargetArrayBody, index, 8), 8)); + 8, 8, c->memory(array, types.i8, TargetArrayBody, index), 8)); break; case saload: frame->pushInt( c->load(2, 2, - c->memory(array, types.i2, TargetArrayBody, index, 2), + c->memory(array, types.i2, TargetArrayBody, index), TargetBytesPerWord)); break; } @@ -4231,21 +4214,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store(types.f4, value, types.f4, - c->memory(array, types.f4, TargetArrayBody, index, 4)); + c->memory(array, types.f4, TargetArrayBody, index)); break; case iastore: c->store(types.address, value, types.i4, - c->memory(array, types.i4, TargetArrayBody, index, 4)); + c->memory(array, types.i4, TargetArrayBody, index)); break; case bastore: c->store(types.address, value, types.i1, - c->memory(array, types.i1, TargetArrayBody, index, 1)); + c->memory(array, types.i1, TargetArrayBody, index)); break; case castore: @@ -4253,21 +4236,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store(types.address, value, types.i2, - c->memory(array, types.i2, TargetArrayBody, index, 2)); + c->memory(array, types.i2, TargetArrayBody, index)); break; case dastore: c->store(types.f8, value, types.f8, - c->memory(array, types.f8, TargetArrayBody, index, 8)); + c->memory(array, types.f8, TargetArrayBody, index)); break; case lastore: c->store(types.i8, value, types.i8, - c->memory(array, types.i8, TargetArrayBody, index, 8)); + c->memory(array, types.i8, TargetArrayBody, index)); break; } } break; @@ -4335,11 +4318,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto next; case arraylength: { - frame->pushInt(c->load( - TargetBytesPerWord, - TargetBytesPerWord, - c->memory(frame->popObject(), types.i4, TargetArrayLength, 0, 1), - TargetBytesPerWord)); + frame->pushInt( + c->load(TargetBytesPerWord, + TargetBytesPerWord, + c->memory(frame->popObject(), types.i4, TargetArrayLength), + TargetBytesPerWord)); } break; case astore: @@ -4660,8 +4643,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( 1, 1, - c->memory( - table, types.i4, targetFieldOffset(context, field), 0, 1), + c->memory(table, types.i4, targetFieldOffset(context, field)), TargetBytesPerWord)); break; @@ -4669,8 +4651,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->loadz( 2, 2, - c->memory( - table, types.i4, targetFieldOffset(context, field), 0, 1), + c->memory(table, types.i4, targetFieldOffset(context, field)), TargetBytesPerWord)); break; @@ -4678,8 +4659,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( 2, 2, - c->memory( - table, types.i4, targetFieldOffset(context, field), 0, 1), + c->memory(table, types.i4, targetFieldOffset(context, field)), TargetBytesPerWord)); break; @@ -4687,8 +4667,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( 4, 4, - c->memory( - table, types.f4, targetFieldOffset(context, field), 0, 1), + c->memory(table, types.f4, targetFieldOffset(context, field)), TargetBytesPerWord)); break; @@ -4696,8 +4675,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( 4, 4, - c->memory( - table, types.i4, targetFieldOffset(context, field), 0, 1), + c->memory(table, types.i4, targetFieldOffset(context, field)), TargetBytesPerWord)); break; @@ -4705,8 +4683,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushLong(c->load( 8, 8, - c->memory( - table, types.f8, targetFieldOffset(context, field), 0, 1), + c->memory(table, types.f8, targetFieldOffset(context, field)), 8)); break; @@ -4714,8 +4691,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushLong(c->load( 8, 8, - c->memory( - table, types.i8, targetFieldOffset(context, field), 0, 1), + c->memory(table, types.i8, targetFieldOffset(context, field)), 8)); break; @@ -4723,8 +4699,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushObject(c->load( TargetBytesPerWord, TargetBytesPerWord, - c->memory( - table, types.object, targetFieldOffset(context, field), 0, 1), + c->memory(table, types.object, targetFieldOffset(context, field)), TargetBytesPerWord)); break; @@ -5202,15 +5177,12 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, unsigned rSize = resultSize(t, methodReturnCode(t, target)); Compiler::Operand* result = c->stackCall( - c->memory( - c->binaryOp(lir::And, - types.address, - c->constant(TargetPointerMask, types.i4), - c->memory(instance, types.object, 0, 0, 1)), - types.object, - offset, - 0, - 1), + c->memory(c->binaryOp(lir::And, + types.address, + c->constant(TargetPointerMask, types.i4), + c->memory(instance, types.object)), + types.object, + offset), tailCall ? Compiler::TailJump : 0, frame->trace(0, 0), rSize, @@ -5227,7 +5199,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, // (e.g. readObject and writeObject for serialization), so // we must handle such cases here. - compileDirectInvoke(t, frame, target, tailCall); + compileDirectInvoke(t, frame, target, tailCall); } } } else { @@ -5833,8 +5805,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address, value, types.i1, - c->memory( - table, types.i4, targetFieldOffset(context, field), 0, 1)); + c->memory(table, types.i4, targetFieldOffset(context, field))); break; case CharField: @@ -5843,8 +5814,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address, value, types.i2, - c->memory( - table, types.i4, targetFieldOffset(context, field), 0, 1)); + c->memory(table, types.i4, targetFieldOffset(context, field))); break; case FloatField: @@ -5852,8 +5822,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.f4, value, types.f4, - c->memory( - table, types.f4, targetFieldOffset(context, field), 0, 1)); + c->memory(table, types.f4, targetFieldOffset(context, field))); break; case IntField: @@ -5861,8 +5830,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address, value, types.i4, - c->memory( - table, types.i4, targetFieldOffset(context, field), 0, 1)); + c->memory(table, types.i4, targetFieldOffset(context, field))); break; case DoubleField: @@ -5870,8 +5838,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.f8, value, types.f8, - c->memory( - table, types.f4, targetFieldOffset(context, field), 0, 1)); + c->memory(table, types.f4, targetFieldOffset(context, field))); break; case LongField: @@ -5879,8 +5846,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.i8, value, types.i8, - c->memory( - table, types.i4, targetFieldOffset(context, field), 0, 1)); + c->memory(table, types.i4, targetFieldOffset(context, field))); break; case ObjectField: @@ -6222,8 +6188,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, = c->memory(frame->absoluteAddressOperand(s->start), types.address, 0, - normalizedKey, - TargetBytesPerWord); + normalizedKey); c->jmp(c->load(TargetBytesPerWord, TargetBytesPerWord, From 1d466a800ecfa67fbbd253e638aec36e8f427db0 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 23:52:02 -0600 Subject: [PATCH 18/89] remove redundant Compiler::call resultSize parameter --- include/avian/codegen/compiler.h | 1 - src/codegen/compiler.cpp | 12 ++++++--- src/compile.cpp | 43 -------------------------------- 3 files changed, 9 insertions(+), 47 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index d09a56dba2..75f3d4419e 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -84,7 +84,6 @@ class Compiler { virtual Operand* call(Operand* address, unsigned flags, TraceHandler* traceHandler, - unsigned resultSize, ir::Type resultType, unsigned argumentCount, ...) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index d5e4a2c5c3..105468a696 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2442,7 +2442,6 @@ class MyCompiler: public Compiler { virtual Operand* call(Operand* address, unsigned flags, TraceHandler* traceHandler, - unsigned resultSize, ir::Type resultType, unsigned argumentCount, ...) @@ -2482,8 +2481,15 @@ class MyCompiler: public Compiler { } Value* result = value(&c, resultType); - appendCall(&c, static_cast(address), flags, traceHandler, result, - resultSize, argumentStack, index, 0); + appendCall(&c, + static_cast(address), + flags, + traceHandler, + result, + resultType.size(), + argumentStack, + index, + 0); return result; } diff --git a/src/compile.cpp b/src/compile.cpp index 16dacf6ce3..6b121ec142 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3157,7 +3157,6 @@ void compileSafePoint(MyThread* t, Compiler* c, Frame* frame) { c->call(c->constant(getThunk(t, idleIfNecessaryThunk), types.address), 0, frame->trace(0, 0), - 0, types.void_, 1, c->threadRegister()); @@ -3360,7 +3359,6 @@ compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk, c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), - TargetBytesPerWord, types.address, 2, c->threadRegister(), @@ -3408,7 +3406,6 @@ compileDirectAbstractInvoke(MyThread* t, Frame* frame, Thunk thunk, c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), - TargetBytesPerWord, types.address, 2, c->threadRegister(), @@ -3437,7 +3434,6 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) c->call(c->constant(function, types.address), 0, frame->trace(0, 0), - 0, types.void_, 2, c->threadRegister(), @@ -4068,7 +4064,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->call(c->constant(getThunk(t, gcIfNecessaryThunk), types.address), 0, frame->trace(0, 0), - 0, types.void_, 1, c->threadRegister()); @@ -4194,7 +4189,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->call(c->constant(getThunk(t, setMaybeNullThunk), types.address), 0, frame->trace(0, 0), - 0, types.void_, 4, c->threadRegister(), @@ -4304,7 +4298,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushObject(c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), - TargetBytesPerWord, types.object, 3, c->threadRegister(), @@ -4350,7 +4343,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->call(c->constant(getThunk(t, throw_Thunk), types.address), Compiler::NoReturn, frame->trace(0, 0), - 0, types.void_, 2, c->threadRegister(), @@ -4389,7 +4381,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), - 0, types.void_, 3, c->threadRegister(), @@ -4432,7 +4423,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->constant(getThunk(t, compareDoublesGThunk), types.address), 0, 0, - 4, types.i4, 4, static_cast(0), @@ -4453,7 +4443,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->constant(getThunk(t, compareDoublesLThunk), types.address), 0, 0, - 4, types.i4, 4, static_cast(0), @@ -4534,7 +4523,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->constant(getThunk(t, compareFloatsGThunk), types.address), 0, 0, - 4, types.i4, 2, a, @@ -4553,7 +4541,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->constant(getThunk(t, compareFloatsLThunk), types.address), 0, 0, - 4, types.i4, 2, a, @@ -4600,7 +4587,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - 0, types.void_, 2, c->threadRegister(), @@ -4618,7 +4604,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->call(c->constant(getThunk(t, tryInitClassThunk), types.address), 0, frame->trace(0, 0), - 0, types.void_, 2, c->threadRegister(), @@ -4716,7 +4701,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - 0, types.void_, 2, c->threadRegister(), @@ -4731,7 +4715,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, object pair = makePair(t, context->method, reference); - unsigned rSize = resultSize(t, fieldCode); ir::Type rType = operandTypeForFieldCode(t, fieldCode); Compiler::Operand* result; @@ -4741,7 +4724,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - rSize, rType, 2, c->threadRegister(), @@ -4754,7 +4736,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - rSize, rType, 3, c->threadRegister(), @@ -5018,7 +4999,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), - 4, types.i4, 3, c->threadRegister(), @@ -5068,7 +5048,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, = c->stackCall(c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), - TargetBytesPerWord, types.address, 3, c->threadRegister(), @@ -5215,7 +5194,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - TargetBytesPerWord, types.address, 3, c->threadRegister(), @@ -5338,7 +5316,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->call(c->constant(getThunk(t, compareLongsThunk), types.address), 0, 0, - 4, types.i4, 4, static_cast(0), @@ -5385,7 +5362,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - TargetBytesPerWord, types.object, 2, c->threadRegister(), @@ -5399,7 +5375,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->constant(getThunk(t, getJClass64Thunk), types.address), 0, frame->trace(0, 0), - TargetBytesPerWord, types.object, 2, c->threadRegister(), @@ -5510,7 +5485,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->constant(getThunk(t, lookUpAddressThunk), types.address), 0, 0, - TargetBytesPerWord, types.address, 4, key, @@ -5601,7 +5575,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->constant(getThunk(t, acquireMonitorForObjectThunk), types.address), 0, frame->trace(0, 0), - 0, types.void_, 2, c->threadRegister(), @@ -5614,7 +5587,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->constant(getThunk(t, releaseMonitorForObjectThunk), types.address), 0, frame->trace(0, 0), - 0, types.void_, 2, c->threadRegister(), @@ -5651,7 +5623,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, = c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), - TargetBytesPerWord, types.object, 4, c->threadRegister(), @@ -5690,7 +5661,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushObject(c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), - TargetBytesPerWord, types.object, 2, c->threadRegister(), @@ -5706,7 +5676,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->call(c->constant(getThunk(t, makeBlankArrayThunk), types.address), 0, frame->trace(0, 0), - TargetBytesPerWord, types.object, 3, c->threadRegister(), @@ -5749,7 +5718,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->call(c->constant(getThunk(t, tryInitClassThunk), types.address), 0, frame->trace(0, 0), - 0, types.void_, 2, c->threadRegister(), @@ -5776,7 +5744,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - 0, types.void_, 2, c->threadRegister(), @@ -5854,7 +5821,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->call(c->constant(getThunk(t, setMaybeNullThunk), types.address), 0, frame->trace(0, 0), - 0, types.void_, 4, c->threadRegister(), @@ -5863,7 +5829,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, value); } else { c->call(c->constant(getThunk(t, setThunk), types.address), - 0, 0, 0, types.void_, @@ -5886,7 +5851,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - 0, types.void_, 2, c->threadRegister(), @@ -5900,7 +5864,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, (t, byteArrayBody(t, referenceSpec(t, reference), 0)); Compiler::Operand* value = popField(t, frame, fieldCode); - unsigned rSize = resultSize(t, fieldCode); ir::Type rType = operandTypeForFieldCode(t, fieldCode); object pair = makePair(t, context->method, reference); @@ -5918,7 +5881,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - rSize, rType, 3, c->threadRegister(), @@ -5931,7 +5893,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - rSize, rType, 4, c->threadRegister(), @@ -5949,7 +5910,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - rSize, rType, 4, c->threadRegister(), @@ -5964,7 +5924,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - rSize, rType, 5, c->threadRegister(), @@ -5983,7 +5942,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - rSize, rType, 3, c->threadRegister(), @@ -5997,7 +5955,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address), 0, frame->trace(0, 0), - rSize, rType, 4, c->threadRegister(), From 8b1739dc0f14f30d4d7962bbd203bf57c2f2f532 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 23:54:25 -0600 Subject: [PATCH 19/89] remove redundant Compiler::stackCall resultSize parameter --- include/avian/codegen/compiler.h | 1 - src/codegen/compiler.cpp | 12 +++++++++--- src/compile.cpp | 28 ++++++++++------------------ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 75f3d4419e..02be4a3e1b 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -91,7 +91,6 @@ class Compiler { virtual Operand* stackCall(Operand* address, unsigned flags, TraceHandler* traceHandler, - unsigned resultSize, ir::Type resultType, unsigned argumentFootprint) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 105468a696..6c824efce8 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2497,13 +2497,19 @@ class MyCompiler: public Compiler { virtual Operand* stackCall(Operand* address, unsigned flags, TraceHandler* traceHandler, - unsigned resultSize, ir::Type resultType, unsigned argumentFootprint) { Value* result = value(&c, resultType); - appendCall(&c, static_cast(address), flags, traceHandler, result, - resultSize, c.stack, 0, argumentFootprint); + appendCall(&c, + static_cast(address), + flags, + traceHandler, + result, + resultType.size(), + c.stack, + 0, + argumentFootprint); return result; } diff --git a/src/compile.cpp b/src/compile.cpp index 6b121ec142..8165571427 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3162,9 +3162,12 @@ void compileSafePoint(MyThread* t, Compiler* c, Frame* frame) { c->threadRegister()); } -Compiler::Operand* -compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall, - bool useThunk, unsigned rSize, avian::codegen::Promise* addressPromise) +Compiler::Operand* compileDirectInvoke(MyThread* t, + Frame* frame, + object target, + bool tailCall, + bool useThunk, + avian::codegen::Promise* addressPromise) { avian::codegen::Compiler* c = frame->c; ir::Types types(TargetBytesPerWord); @@ -3199,7 +3202,6 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall, c->promiseConstant(returnAddressPromise, types.address), flags, trace, - rSize, operandTypeForFieldCode(t, methodReturnCode(t, target)), methodParameterFootprint(t, target)); @@ -3221,7 +3223,6 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall, c->constant(defaultThunk(t), types.address), flags, frame->trace(target, traceFlags), - rSize, operandTypeForFieldCode(t, methodReturnCode(t, target)), methodParameterFootprint(t, target)); } @@ -3236,7 +3237,6 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall, flags, tailCall ? 0 : frame->trace ((methodFlags(t, target) & ACC_NATIVE) ? target : 0, 0), - rSize, operandTypeForFieldCode(t, methodReturnCode(t, target)), methodParameterFootprint(t, target)); } @@ -3269,20 +3269,16 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall) object pointer = makePointer(t, p); bc->calls = makeTriple(t, target, pointer, bc->calls); - result = compileDirectInvoke - (t, frame, target, tailCall, false, rSize, p); + result = compileDirectInvoke(t, frame, target, tailCall, false, p); } else { - result = compileDirectInvoke - (t, frame, target, tailCall, true, rSize, 0); + result = compileDirectInvoke(t, frame, target, tailCall, true, 0); } } else if (unresolved(t, methodAddress(t, target)) or classNeedsInit(t, methodClass(t, target))) { - result = compileDirectInvoke - (t, frame, target, tailCall, true, rSize, 0); + result = compileDirectInvoke(t, frame, target, tailCall, true, 0); } else { - result = compileDirectInvoke - (t, frame, target, tailCall, false, rSize, 0); + result = compileDirectInvoke(t, frame, target, tailCall, false, 0); } } @@ -3332,7 +3328,6 @@ compileReferenceInvoke(MyThread* t, Frame* frame, Compiler::Operand* method, (method, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0), - rSize, operandTypeForFieldCode(t, returnCode), parameterFootprint); @@ -3383,7 +3378,6 @@ compileAbstractInvoke(MyThread* t, Frame* frame, Compiler::Operand* method, (method, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0), - rSize, operandTypeForFieldCode(t, returnCode), parameterFootprint); @@ -5055,7 +5049,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->peek(1, parameterFootprint - 1)), tailCall ? Compiler::TailJump : 0, frame->trace(0, 0), - rSize, operandTypeForFieldCode(t, returnCode), parameterFootprint); @@ -5164,7 +5157,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, offset), tailCall ? Compiler::TailJump : 0, frame->trace(0, 0), - rSize, operandTypeForFieldCode(t, methodReturnCode(t, target)), parameterFootprint); From 0ee3eec478ef94e6de431ef70b30142d4b1439c3 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 00:01:14 -0600 Subject: [PATCH 20/89] add extra type checks to Compiler::store --- src/codegen/compiler.cpp | 1 + src/compile.cpp | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 6c824efce8..39cfc1d51e 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2619,6 +2619,7 @@ class MyCompiler: public Compiler { assert(&c, srcType.flavor() != ir::Type::Float || srcType.size() == static_cast(src)->type.size()); + assert(&c, dstType == static_cast(dst)->type); appendMove(&c, lir::Move, srcType.size(), diff --git a/src/compile.cpp b/src/compile.cpp index 8165571427..be02803e96 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3746,7 +3746,7 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* address = popLongAddress(frame); frame->popObject(); frame->pushInt( - c->load(1, 1, c->memory(address, types.i4), TargetBytesPerWord)); + c->load(1, 1, c->memory(address, types.i1), TargetBytesPerWord)); return true; } else if (MATCH(methodName(t, target), "putByte") and MATCH(methodSpec(t, target), "(JB)V")) @@ -3754,7 +3754,7 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(types.address, value, types.i1, c->memory(address, types.i4)); + c->store(types.address, value, types.i1, c->memory(address, types.i1)); return true; } else if ((MATCH(methodName(t, target), "getShort") and MATCH(methodSpec(t, target), "(J)S")) @@ -3764,7 +3764,7 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* address = popLongAddress(frame); frame->popObject(); frame->pushInt( - c->load(2, 2, c->memory(address, types.i4), TargetBytesPerWord)); + c->load(2, 2, c->memory(address, types.i2), TargetBytesPerWord)); return true; } else if ((MATCH(methodName(t, target), "putShort") and MATCH(methodSpec(t, target), "(JS)V")) @@ -3774,7 +3774,7 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(types.address, value, types.i2, c->memory(address, types.i4)); + c->store(types.address, value, types.i2, c->memory(address, types.i2)); return true; } else if ((MATCH(methodName(t, target), "getInt") and MATCH(methodSpec(t, target), "(J)I")) @@ -3814,8 +3814,8 @@ intrinsic(MyThread* t, Frame* frame, object target) c->load(8, 8, c->memory(address, - MATCH(methodName(t, target), "getLong") ? types.i4 - : types.f4), + MATCH(methodName(t, target), "getLong") ? types.i8 + : types.f8), 8)); return true; } else if ((MATCH(methodName(t, target), "putLong") @@ -5764,7 +5764,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address, value, types.i1, - c->memory(table, types.i4, targetFieldOffset(context, field))); + c->memory(table, types.i1, targetFieldOffset(context, field))); break; case CharField: @@ -5773,7 +5773,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.address, value, types.i2, - c->memory(table, types.i4, targetFieldOffset(context, field))); + c->memory(table, types.i2, targetFieldOffset(context, field))); break; case FloatField: @@ -5797,7 +5797,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.f8, value, types.f8, - c->memory(table, types.f4, targetFieldOffset(context, field))); + c->memory(table, types.f8, targetFieldOffset(context, field))); break; case LongField: @@ -5805,7 +5805,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.i8, value, types.i8, - c->memory(table, types.i4, targetFieldOffset(context, field))); + c->memory(table, types.i8, targetFieldOffset(context, field))); break; case ObjectField: From 9c98986f99ea88ac849c65d3d1a921bf3acee8a7 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 00:04:51 -0600 Subject: [PATCH 21/89] remove redundant Compiler::store dstType parameter --- include/avian/codegen/compiler.h | 1 - src/codegen/compiler.cpp | 7 ++----- src/compile.cpp | 24 +++++------------------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 02be4a3e1b..17f702a68e 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -109,7 +109,6 @@ class Compiler { virtual void store(ir::Type srcType, Operand* src, - ir::Type dstType, Operand* dst) = 0; virtual Operand* load(unsigned srcSize, unsigned srcSelectSize, Operand* src, unsigned dstSize) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 39cfc1d51e..8b0cfff78c 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2610,22 +2610,19 @@ class MyCompiler: public Compiler { virtual void store(ir::Type srcType, Operand* src, - ir::Type dstType, Operand* dst) { assert(&c, srcType.flavor() == static_cast(src)->type.flavor()); - assert(&c, dstType.flavor() == static_cast(dst)->type.flavor()); - assert(&c, srcType.flavor() == dstType.flavor()); + assert(&c, srcType.flavor() == static_cast(dst)->type.flavor()); assert(&c, srcType.flavor() != ir::Type::Float || srcType.size() == static_cast(src)->type.size()); - assert(&c, dstType == static_cast(dst)->type); appendMove(&c, lir::Move, srcType.size(), srcType.size(), static_cast(src), - dstType.size(), + static_cast(dst)->type.size(), static_cast(dst)); } diff --git a/src/compile.cpp b/src/compile.cpp index be02803e96..7e6411adbb 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3208,7 +3208,6 @@ Compiler::Operand* compileDirectInvoke(MyThread* t, c->store( types.address, frame->absoluteAddressOperand(returnAddressPromise), - types.address, c->memory( c->threadRegister(), types.address, TARGET_THREAD_TAILADDRESS)); @@ -3754,7 +3753,7 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(types.address, value, types.i1, c->memory(address, types.i1)); + c->store(types.address, value, c->memory(address, types.i1)); return true; } else if ((MATCH(methodName(t, target), "getShort") and MATCH(methodSpec(t, target), "(J)S")) @@ -3774,7 +3773,7 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popInt(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store(types.address, value, types.i2, c->memory(address, types.i2)); + c->store(types.address, value, c->memory(address, types.i2)); return true; } else if ((MATCH(methodName(t, target), "getInt") and MATCH(methodSpec(t, target), "(J)I")) @@ -3801,7 +3800,7 @@ intrinsic(MyThread* t, Frame* frame, object target) frame->popObject(); ir::Type type = MATCH(methodName(t, target), "putInt") ? types.i4 : types.f4; - c->store(type, value, type, c->memory(address, type)); + c->store(type, value, c->memory(address, type)); return true; } else if ((MATCH(methodName(t, target), "getLong") and MATCH(methodSpec(t, target), "(J)J")) @@ -3828,7 +3827,7 @@ intrinsic(MyThread* t, Frame* frame, object target) frame->popObject(); ir::Type type = MATCH(methodName(t, target), "putLong") ? types.i8 : types.f8; - c->store(type, value, type, c->memory(address, type)); + c->store(type, value, c->memory(address, type)); return true; } else if (MATCH(methodName(t, target), "getAddress") and MATCH(methodSpec(t, target), "(J)J")) @@ -3846,8 +3845,7 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* value = frame->popLong(); Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - c->store( - types.i8, value, types.address, c->memory(address, types.address)); + c->store(types.i8, value, c->memory(address, types.address)); return true; } } @@ -4201,21 +4199,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case fastore: c->store(types.f4, value, - types.f4, c->memory(array, types.f4, TargetArrayBody, index)); break; case iastore: c->store(types.address, value, - types.i4, c->memory(array, types.i4, TargetArrayBody, index)); break; case bastore: c->store(types.address, value, - types.i1, c->memory(array, types.i1, TargetArrayBody, index)); break; @@ -4223,21 +4218,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case sastore: c->store(types.address, value, - types.i2, c->memory(array, types.i2, TargetArrayBody, index)); break; case dastore: c->store(types.f8, value, - types.f8, c->memory(array, types.f8, TargetArrayBody, index)); break; case lastore: c->store(types.i8, value, - types.i8, c->memory(array, types.i8, TargetArrayBody, index)); break; } @@ -5763,7 +5755,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store( types.address, value, - types.i1, c->memory(table, types.i1, targetFieldOffset(context, field))); break; @@ -5772,7 +5763,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store( types.address, value, - types.i2, c->memory(table, types.i2, targetFieldOffset(context, field))); break; @@ -5780,7 +5770,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store( types.f4, value, - types.f4, c->memory(table, types.f4, targetFieldOffset(context, field))); break; @@ -5788,7 +5777,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store( types.address, value, - types.i4, c->memory(table, types.i4, targetFieldOffset(context, field))); break; @@ -5796,7 +5784,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store( types.f8, value, - types.f8, c->memory(table, types.f8, targetFieldOffset(context, field))); break; @@ -5804,7 +5791,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store( types.i8, value, - types.i8, c->memory(table, types.i8, targetFieldOffset(context, field))); break; From 27ea5032335876eaa87010a7a478b998fb1930dd Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 00:13:39 -0600 Subject: [PATCH 22/89] switch Compiler::load* to use ir::Type rather than sizes --- include/avian/codegen/compiler.h | 12 ++- src/codegen/compiler.cpp | 34 +++++-- src/compile.cpp | 163 +++++++++++++++++-------------- 3 files changed, 119 insertions(+), 90 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 17f702a68e..bc88512f2d 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -110,10 +110,14 @@ class Compiler { virtual void store(ir::Type srcType, Operand* src, Operand* dst) = 0; - virtual Operand* load(unsigned srcSize, unsigned srcSelectSize, Operand* src, - unsigned dstSize) = 0; - virtual Operand* loadz(unsigned size, unsigned srcSelectSize, Operand* src, - unsigned dstSize) = 0; + virtual Operand* load(ir::Type srcType, + ir::Type srcSelectType, + Operand* src, + ir::Type dstType) = 0; + virtual Operand* loadz(ir::Type srcType, + ir::Type srcSelectType, + Operand* src, + ir::Type dstType) = 0; virtual void condJump(lir::TernaryOperation op, unsigned size, diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 8b0cfff78c..ed94ad5dea 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2626,25 +2626,39 @@ class MyCompiler: public Compiler { static_cast(dst)); } - virtual Operand* load(unsigned srcSize, unsigned srcSelectSize, Operand* src, - unsigned dstSize) + virtual Operand* load(ir::Type srcType, + ir::Type srcSelectType, + Operand* src, + ir::Type dstType) { - assert(&c, dstSize >= TargetBytesPerWord); + assert(&c, dstType.size() >= TargetBytesPerWord); Value* dst = value(&c, static_cast(src)->type); - appendMove(&c, lir::Move, srcSize, srcSelectSize, static_cast(src), - dstSize, dst); + appendMove(&c, + lir::Move, + srcType.size(), + srcSelectType.size(), + static_cast(src), + dstType.size(), + dst); return dst; } - virtual Operand* loadz(unsigned srcSize, unsigned srcSelectSize, - Operand* src, unsigned dstSize) + virtual Operand* loadz(ir::Type srcType, + ir::Type srcSelectType, + Operand* src, + ir::Type dstType) { - assert(&c, dstSize >= TargetBytesPerWord); + assert(&c, dstType.size() >= TargetBytesPerWord); Value* dst = value(&c, static_cast(src)->type); - appendMove(&c, lir::MoveZ, srcSize, srcSelectSize, static_cast(src), - dstSize, dst); + appendMove(&c, + lir::MoveZ, + srcType.size(), + srcSelectType.size(), + static_cast(src), + dstType.size(), + dst); return dst; } diff --git a/src/compile.cpp b/src/compile.cpp index 7e6411adbb..0a4cd0ad43 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3702,8 +3702,11 @@ floatBranch(MyThread* t, Frame* frame, object code, unsigned& ip, Compiler::Operand* popLongAddress(Frame* frame) { - return TargetBytesPerWord == 8 ? frame->popLong() : frame->c->load - (8, 8, frame->popLong(), TargetBytesPerWord); + ir::Types types(TargetBytesPerWord); + return TargetBytesPerWord == 8 + ? frame->popLong() + : frame->c->load( + types.i8, types.i8, frame->popLong(), types.address); } bool @@ -3744,8 +3747,8 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushInt( - c->load(1, 1, c->memory(address, types.i1), TargetBytesPerWord)); + frame->pushInt(c->load( + types.i1, types.i1, c->memory(address, types.i1), types.address)); return true; } else if (MATCH(methodName(t, target), "putByte") and MATCH(methodSpec(t, target), "(JB)V")) @@ -3762,8 +3765,8 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushInt( - c->load(2, 2, c->memory(address, types.i2), TargetBytesPerWord)); + frame->pushInt(c->load( + types.i2, types.i2, c->memory(address, types.i2), types.address)); return true; } else if ((MATCH(methodName(t, target), "putShort") and MATCH(methodSpec(t, target), "(JS)V")) @@ -3783,12 +3786,12 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* address = popLongAddress(frame); frame->popObject(); frame->pushInt( - c->load(4, - 4, + c->load(types.i4, + types.i4, c->memory(address, MATCH(methodName(t, target), "getInt") ? types.i4 : types.f4), - TargetBytesPerWord)); + types.address)); return true; } else if ((MATCH(methodName(t, target), "putInt") and MATCH(methodSpec(t, target), "(JI)V")) @@ -3810,12 +3813,12 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* address = popLongAddress(frame); frame->popObject(); frame->pushLong( - c->load(8, - 8, + c->load(types.i8, + types.i8, c->memory(address, MATCH(methodName(t, target), "getLong") ? types.i8 : types.f8), - 8)); + types.i8)); return true; } else if ((MATCH(methodName(t, target), "putLong") and MATCH(methodSpec(t, target), "(JJ)V")) @@ -3834,10 +3837,10 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushLong(c->load(TargetBytesPerWord, - TargetBytesPerWord, + frame->pushLong(c->load(types.address, + types.address, c->memory(address, types.address), - 8)); + types.i8)); return true; } else if (MATCH(methodName(t, target), "putAddress") and MATCH(methodSpec(t, target), "(JJ)V")) @@ -4089,60 +4092,66 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (instruction) { case aaload: frame->pushObject( - c->load(TargetBytesPerWord, - TargetBytesPerWord, + c->load(types.address, + types.address, c->memory(array, types.object, TargetArrayBody, index), - TargetBytesPerWord)); + types.address)); break; case faload: frame->pushInt( - c->load(4, - 4, + c->load(types.f4, + types.f4, c->memory(array, types.f4, TargetArrayBody, index), - TargetBytesPerWord)); + types.address)); break; case iaload: frame->pushInt( - c->load(4, - 4, + c->load(types.i4, + types.i4, c->memory(array, types.i4, TargetArrayBody, index), - TargetBytesPerWord)); + types.address)); break; case baload: frame->pushInt( - c->load(1, - 1, + c->load(types.i1, + types.i1, c->memory(array, types.i1, TargetArrayBody, index), - TargetBytesPerWord)); + types.address)); break; case caload: frame->pushInt( - c->loadz(2, - 2, + c->loadz(types.i2, + types.i2, c->memory(array, types.i2, TargetArrayBody, index), - TargetBytesPerWord)); + types.address)); break; case daload: - frame->pushLong(c->load( - 8, 8, c->memory(array, types.f8, TargetArrayBody, index), 8)); + frame->pushLong( + c->load(types.f8, + types.f8, + c->memory(array, types.f8, TargetArrayBody, index), + types.f8)); break; case laload: - frame->pushLong(c->load( - 8, 8, c->memory(array, types.i8, TargetArrayBody, index), 8)); + frame->pushLong( + c->load(types.i8, + types.i8, + c->memory(array, types.i8, TargetArrayBody, index), + types.i8)); break; case saload: frame->pushInt( - c->load(2, - 2, + c->load(types.i2, + types.i2, c->memory(array, types.i2, TargetArrayBody, index), - TargetBytesPerWord)); + types.address)); break; } } break; @@ -4298,10 +4307,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case arraylength: { frame->pushInt( - c->load(TargetBytesPerWord, - TargetBytesPerWord, + c->load(types.address, + types.address, c->memory(frame->popObject(), types.i4, TargetArrayLength), - TargetBytesPerWord)); + types.address)); } break; case astore: @@ -4612,66 +4621,66 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ByteField: case BooleanField: frame->pushInt(c->load( - 1, - 1, + types.i1, + types.i1, c->memory(table, types.i4, targetFieldOffset(context, field)), - TargetBytesPerWord)); + types.address)); break; case CharField: frame->pushInt(c->loadz( - 2, - 2, + types.i2, + types.i2, c->memory(table, types.i4, targetFieldOffset(context, field)), - TargetBytesPerWord)); + types.address)); break; case ShortField: frame->pushInt(c->load( - 2, - 2, + types.i2, + types.i2, c->memory(table, types.i4, targetFieldOffset(context, field)), - TargetBytesPerWord)); + types.address)); break; case FloatField: frame->pushInt(c->load( - 4, - 4, + types.f4, + types.f4, c->memory(table, types.f4, targetFieldOffset(context, field)), - TargetBytesPerWord)); + types.address)); break; case IntField: frame->pushInt(c->load( - 4, - 4, + types.i4, + types.i4, c->memory(table, types.i4, targetFieldOffset(context, field)), - TargetBytesPerWord)); + types.address)); break; case DoubleField: frame->pushLong(c->load( - 8, - 8, + types.f8, + types.f8, c->memory(table, types.f8, targetFieldOffset(context, field)), - 8)); + types.f8)); break; case LongField: frame->pushLong(c->load( - 8, - 8, + types.i8, + types.i8, c->memory(table, types.i8, targetFieldOffset(context, field)), - 8)); + types.i8)); break; case ObjectField: frame->pushObject(c->load( - TargetBytesPerWord, - TargetBytesPerWord, + types.address, + types.address, c->memory(table, types.object, targetFieldOffset(context, field)), - TargetBytesPerWord)); + types.address)); break; default: @@ -4760,13 +4769,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2b: { - frame->pushInt - (c->load(TargetBytesPerWord, 1, frame->popInt(), TargetBytesPerWord)); + frame->pushInt( + c->load(types.address, types.i1, frame->popInt(), types.address)); } break; case i2c: { - frame->pushInt - (c->loadz(TargetBytesPerWord, 2, frame->popInt(), TargetBytesPerWord)); + frame->pushInt( + c->loadz(types.address, types.i2, frame->popInt(), types.address)); } break; case i2d: { @@ -4778,12 +4787,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2l: - frame->pushLong(c->load(TargetBytesPerWord, 4, frame->popInt(), 8)); + frame->pushLong( + c->load(types.address, types.i4, frame->popInt(), types.i8)); break; case i2s: { - frame->pushInt - (c->load(TargetBytesPerWord, 2, frame->popInt(), TargetBytesPerWord)); + frame->pushInt( + c->load(types.address, types.i2, frame->popInt(), types.address)); } break; case iadd: @@ -5274,7 +5284,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case l2i: - frame->pushInt(c->load(8, 8, frame->popLong(), TargetBytesPerWord)); + frame->pushInt( + c->load(types.i8, types.i8, frame->popLong(), types.address)); break; case ladd: @@ -6125,8 +6136,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, normalizedKey); - c->jmp(c->load(TargetBytesPerWord, - TargetBytesPerWord, + c->jmp(c->load(types.address, + types.address, context->bootContext ? c->binaryOp(lir::Add, types.address, @@ -6135,7 +6146,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TARGET_THREAD_CODEIMAGE), entry) : entry, - TargetBytesPerWord)); + types.address)); s->state = c->saveState(); } goto switchloop; @@ -6143,7 +6154,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case Unswitch: { SwitchState* s = static_cast (stack.peek(sizeof(SwitchState))); - + frame = s->frame(); c->restoreState From 53b68a693dc116ad5db237868c8c83129a410eb0 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 00:20:39 -0600 Subject: [PATCH 23/89] add more aggressive checks to Compiler::load* --- src/codegen/compiler.cpp | 4 ++++ src/compile.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index ed94ad5dea..125284dbd4 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2632,6 +2632,8 @@ class MyCompiler: public Compiler { ir::Type dstType) { assert(&c, dstType.size() >= TargetBytesPerWord); + assert(&c, srcType.flavor() == srcSelectType.flavor()); + assert(&c, srcType.flavor() == dstType.flavor()); Value* dst = value(&c, static_cast(src)->type); appendMove(&c, @@ -2650,6 +2652,8 @@ class MyCompiler: public Compiler { ir::Type dstType) { assert(&c, dstType.size() >= TargetBytesPerWord); + assert(&c, srcType.flavor() == srcSelectType.flavor()); + assert(&c, srcType.flavor() == dstType.flavor()); Value* dst = value(&c, static_cast(src)->type); appendMove(&c, diff --git a/src/compile.cpp b/src/compile.cpp index 0a4cd0ad43..fd9416b5fd 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4103,7 +4103,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->load(types.f4, types.f4, c->memory(array, types.f4, TargetArrayBody, index), - types.address)); + types.f8)); break; case iaload: @@ -4648,7 +4648,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.f4, types.f4, c->memory(table, types.f4, targetFieldOffset(context, field)), - types.address)); + types.f8)); break; case IntField: From 85f114ea0f1d0ae3a9af182e635f87f9099fef5e Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 07:18:12 -0600 Subject: [PATCH 24/89] use ir::Type in Compiler::loadLocal --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 45 ++++++++++++++++---------------- src/compile.cpp | 41 +++++++++++++++++++---------- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index bc88512f2d..19c3068406 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -101,7 +101,7 @@ class Compiler { virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0; virtual void storeLocal(unsigned footprint, Operand* src, unsigned index) = 0; - virtual Operand* loadLocal(unsigned footprint, unsigned index) = 0; + virtual Operand* loadLocal(ir::Type type, unsigned index) = 0; virtual void saveLocals() = 0; virtual void checkBounds(Operand* object, unsigned lengthOffset, diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 125284dbd4..3472fdcc6c 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -1214,9 +1214,27 @@ storeLocal(Context* c, unsigned footprint, Value* v, unsigned index, bool copy) return v; } -Value* -loadLocal(Context* c, unsigned footprint, unsigned index) +unsigned typeFootprint(Context* c, ir::Type type) { + // TODO: this function is very Java-specific in nature. Generalize. + switch (type.flavor()) { + case ir::Type::Float: + case ir::Type::Integer: + return type.size() / 4; + case ir::Type::Object: + case ir::Type::Address: + case ir::Type::Half: + return 1; + case ir::Type::Void: + return 0; + default: + abort(c); + } +} + +Value* loadLocal(Context* c, ir::Type type, unsigned index) +{ + unsigned footprint = typeFootprint(c, type); assert(c, index + footprint <= c->localFootprint); if (footprint > 1) { @@ -2103,24 +2121,6 @@ class Client: public Assembler::Client { Context* c; }; -unsigned typeFootprint(Context* c, ir::Type type) -{ - // TODO: this function is very Java-specific in nature. Generalize. - switch (type.flavor()) { - case ir::Type::Float: - case ir::Type::Integer: - return type.size() / 4; - case ir::Type::Object: - case ir::Type::Address: - case ir::Type::Half: - return 1; - case ir::Type::Void: - return 0; - default: - abort(c); - } -} - class MyCompiler: public Compiler { public: MyCompiler(System* s, Assembler* assembler, Zone* zone, @@ -2593,8 +2593,9 @@ class MyCompiler: public Compiler { compiler::storeLocal(&c, footprint, static_cast(src), index, true); } - virtual Operand* loadLocal(unsigned footprint, unsigned index) { - return compiler::loadLocal(&c, footprint, index); + virtual Operand* loadLocal(ir::Type type, unsigned index) + { + return compiler::loadLocal(&c, type, index); } virtual void saveLocals() { diff --git a/src/compile.cpp b/src/compile.cpp index fd9416b5fd..6d8ad0c7bf 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1331,11 +1331,13 @@ translateLocalIndex(Context* context, unsigned footprint, unsigned index) } } -Compiler::Operand* -loadLocal(Context* context, unsigned footprint, unsigned index) +Compiler::Operand* loadLocal(Context* context, + unsigned footprint, + ir::Type type, + unsigned index) { - return context->compiler->loadLocal - (footprint, translateLocalIndex(context, footprint, index)); + return context->compiler->loadLocal( + type, translateLocalIndex(context, footprint, index)); } void @@ -1746,17 +1748,17 @@ class Frame { void loadInt(unsigned index) { assert(t, index < localSize()); - pushInt(loadLocal(context, 1, index)); + pushInt(loadLocal(context, 1, types.i4, index)); } void loadLong(unsigned index) { assert(t, index < static_cast(localSize() - 1)); - pushLong(loadLocal(context, 2, index)); + pushLong(loadLocal(context, 2, types.i8, index)); } void loadObject(unsigned index) { assert(t, index < localSize()); - pushObject(loadLocal(context, 1, index)); + pushObject(loadLocal(context, 1, types.object, index)); } void storeInt(unsigned index) { @@ -1973,8 +1975,12 @@ class Frame { } void returnFromSubroutine(unsigned returnAddressLocal) { - c->returnFromSubroutine - (subroutine->handle, loadLocal(context, 1, returnAddressLocal)); + c->returnFromSubroutine( + subroutine->handle, + loadLocal(context, + 1, + ir::Type(ir::Type::Address, TargetBytesPerWord), + returnAddressLocal)); subroutine->stackIndex = localOffsetFromStack (t, translateLocalIndex(context, 1, returnAddressLocal), @@ -3421,7 +3427,8 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) lock = frame->append(methodClass(t, method)); } else { - lock = loadLocal(frame->context, 1, savedTargetIndex(t, method)); + lock = loadLocal( + frame->context, 1, frame->types.object, savedTargetIndex(t, method)); } c->call(c->constant(function, types.address), @@ -3444,7 +3451,10 @@ handleEntrance(MyThread* t, Frame* frame) { // save 'this' pointer in case it is overwritten. unsigned index = savedTargetIndex(t, method); - storeLocal(frame->context, 1, loadLocal(frame->context, 1, 0), index); + storeLocal(frame->context, + 1, + loadLocal(frame->context, 1, frame->types.object, 0), + index); frame->set(index, Frame::Object); } @@ -4937,7 +4947,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->binaryOp(lir::Add, types.i4, c->constant(count, types.i4), - loadLocal(context, 1, index)), + loadLocal(context, 1, types.i4, index)), index); } break; @@ -6047,7 +6057,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->binaryOp(lir::Add, types.i4, c->constant(count, types.i4), - loadLocal(context, 1, index)), + loadLocal(context, 1, types.i4, index)), index); } break; @@ -6069,7 +6079,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ret: { unsigned index = codeReadInt16(t, code, ip); - c->jmp(loadLocal(context, 1, index)); + c->jmp(loadLocal(context, + 1, + ir::Type(ir::Type::Address, TargetBytesPerWord), + index)); frame->returnFromSubroutine(index); } goto next; From 99fa5602574ec524a3e1322d8347c0faa291cd7c Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 11:13:52 -0600 Subject: [PATCH 25/89] merge Compiler::load and Compiler::loadz --- include/avian/codegen/compiler.h | 7 +- include/avian/codegen/ir.h | 2 + src/codegen/compiler.cpp | 25 +------ src/compile.cpp | 108 +++++++++++++++++++++---------- 4 files changed, 80 insertions(+), 62 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 19c3068406..8597d97604 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -110,14 +110,11 @@ class Compiler { virtual void store(ir::Type srcType, Operand* src, Operand* dst) = 0; - virtual Operand* load(ir::Type srcType, + virtual Operand* load(ir::SignExtendMode signExtend, + ir::Type srcType, ir::Type srcSelectType, Operand* src, ir::Type dstType) = 0; - virtual Operand* loadz(ir::Type srcType, - ir::Type srcSelectType, - Operand* src, - ir::Type dstType) = 0; virtual void condJump(lir::TernaryOperation op, unsigned size, diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h index 09810b5b08..e1870f8e57 100644 --- a/include/avian/codegen/ir.h +++ b/include/avian/codegen/ir.h @@ -113,6 +113,8 @@ class Types { } }; +enum SignExtendMode { SignExtend, ZeroExtend }; + } // namespace ir } // namespace codegen } // namespace avian diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 3472fdcc6c..307cbeb6cb 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2627,7 +2627,8 @@ class MyCompiler: public Compiler { static_cast(dst)); } - virtual Operand* load(ir::Type srcType, + virtual Operand* load(ir::SignExtendMode signExtend, + ir::Type srcType, ir::Type srcSelectType, Operand* src, ir::Type dstType) @@ -2638,27 +2639,7 @@ class MyCompiler: public Compiler { Value* dst = value(&c, static_cast(src)->type); appendMove(&c, - lir::Move, - srcType.size(), - srcSelectType.size(), - static_cast(src), - dstType.size(), - dst); - return dst; - } - - virtual Operand* loadz(ir::Type srcType, - ir::Type srcSelectType, - Operand* src, - ir::Type dstType) - { - assert(&c, dstType.size() >= TargetBytesPerWord); - assert(&c, srcType.flavor() == srcSelectType.flavor()); - assert(&c, srcType.flavor() == dstType.flavor()); - - Value* dst = value(&c, static_cast(src)->type); - appendMove(&c, - lir::MoveZ, + signExtend == ir::SignExtend ? lir::Move : lir::MoveZ, srcType.size(), srcSelectType.size(), static_cast(src), diff --git a/src/compile.cpp b/src/compile.cpp index 6d8ad0c7bf..05bd158c8c 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3713,10 +3713,12 @@ Compiler::Operand* popLongAddress(Frame* frame) { ir::Types types(TargetBytesPerWord); - return TargetBytesPerWord == 8 - ? frame->popLong() - : frame->c->load( - types.i8, types.i8, frame->popLong(), types.address); + return TargetBytesPerWord == 8 ? frame->popLong() + : frame->c->load(ir::SignExtend, + types.i8, + types.i8, + frame->popLong(), + types.address); } bool @@ -3757,8 +3759,11 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushInt(c->load( - types.i1, types.i1, c->memory(address, types.i1), types.address)); + frame->pushInt(c->load(ir::SignExtend, + types.i1, + types.i1, + c->memory(address, types.i1), + types.address)); return true; } else if (MATCH(methodName(t, target), "putByte") and MATCH(methodSpec(t, target), "(JB)V")) @@ -3775,8 +3780,11 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushInt(c->load( - types.i2, types.i2, c->memory(address, types.i2), types.address)); + frame->pushInt(c->load(ir::SignExtend, + types.i2, + types.i2, + c->memory(address, types.i2), + types.address)); return true; } else if ((MATCH(methodName(t, target), "putShort") and MATCH(methodSpec(t, target), "(JS)V")) @@ -3796,7 +3804,8 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* address = popLongAddress(frame); frame->popObject(); frame->pushInt( - c->load(types.i4, + c->load(ir::SignExtend, + types.i4, types.i4, c->memory(address, MATCH(methodName(t, target), "getInt") ? types.i4 @@ -3823,7 +3832,8 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* address = popLongAddress(frame); frame->popObject(); frame->pushLong( - c->load(types.i8, + c->load(ir::SignExtend, + types.i8, types.i8, c->memory(address, MATCH(methodName(t, target), "getLong") ? types.i8 @@ -3847,7 +3857,8 @@ intrinsic(MyThread* t, Frame* frame, object target) { Compiler::Operand* address = popLongAddress(frame); frame->popObject(); - frame->pushLong(c->load(types.address, + frame->pushLong(c->load(ir::SignExtend, + types.address, types.address, c->memory(address, types.address), types.i8)); @@ -4102,7 +4113,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (instruction) { case aaload: frame->pushObject( - c->load(types.address, + c->load(ir::SignExtend, + types.address, types.address, c->memory(array, types.object, TargetArrayBody, index), types.address)); @@ -4110,7 +4122,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case faload: frame->pushInt( - c->load(types.f4, + c->load(ir::SignExtend, + types.f4, types.f4, c->memory(array, types.f4, TargetArrayBody, index), types.f8)); @@ -4118,7 +4131,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case iaload: frame->pushInt( - c->load(types.i4, + c->load(ir::SignExtend, + types.i4, types.i4, c->memory(array, types.i4, TargetArrayBody, index), types.address)); @@ -4126,7 +4140,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case baload: frame->pushInt( - c->load(types.i1, + c->load(ir::SignExtend, + types.i1, types.i1, c->memory(array, types.i1, TargetArrayBody, index), types.address)); @@ -4134,15 +4149,17 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case caload: frame->pushInt( - c->loadz(types.i2, - types.i2, - c->memory(array, types.i2, TargetArrayBody, index), - types.address)); + c->load(ir::ZeroExtend, + types.i2, + types.i2, + c->memory(array, types.i2, TargetArrayBody, index), + types.address)); break; case daload: frame->pushLong( - c->load(types.f8, + c->load(ir::SignExtend, + types.f8, types.f8, c->memory(array, types.f8, TargetArrayBody, index), types.f8)); @@ -4150,7 +4167,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case laload: frame->pushLong( - c->load(types.i8, + c->load(ir::SignExtend, + types.i8, types.i8, c->memory(array, types.i8, TargetArrayBody, index), types.i8)); @@ -4158,7 +4176,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case saload: frame->pushInt( - c->load(types.i2, + c->load(ir::SignExtend, + types.i2, types.i2, c->memory(array, types.i2, TargetArrayBody, index), types.address)); @@ -4317,7 +4336,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case arraylength: { frame->pushInt( - c->load(types.address, + c->load(ir::SignExtend, + types.address, types.address, c->memory(frame->popObject(), types.i4, TargetArrayLength), types.address)); @@ -4631,6 +4651,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ByteField: case BooleanField: frame->pushInt(c->load( + ir::SignExtend, types.i1, types.i1, c->memory(table, types.i4, targetFieldOffset(context, field)), @@ -4638,7 +4659,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case CharField: - frame->pushInt(c->loadz( + frame->pushInt(c->load( + ir::ZeroExtend, types.i2, types.i2, c->memory(table, types.i4, targetFieldOffset(context, field)), @@ -4647,6 +4669,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ShortField: frame->pushInt(c->load( + ir::SignExtend, types.i2, types.i2, c->memory(table, types.i4, targetFieldOffset(context, field)), @@ -4655,6 +4678,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case FloatField: frame->pushInt(c->load( + ir::SignExtend, types.f4, types.f4, c->memory(table, types.f4, targetFieldOffset(context, field)), @@ -4663,6 +4687,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case IntField: frame->pushInt(c->load( + ir::SignExtend, types.i4, types.i4, c->memory(table, types.i4, targetFieldOffset(context, field)), @@ -4671,6 +4696,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case DoubleField: frame->pushLong(c->load( + ir::SignExtend, types.f8, types.f8, c->memory(table, types.f8, targetFieldOffset(context, field)), @@ -4679,6 +4705,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case LongField: frame->pushLong(c->load( + ir::SignExtend, types.i8, types.i8, c->memory(table, types.i8, targetFieldOffset(context, field)), @@ -4687,6 +4714,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ObjectField: frame->pushObject(c->load( + ir::SignExtend, types.address, types.address, c->memory(table, types.object, targetFieldOffset(context, field)), @@ -4779,13 +4807,19 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2b: { - frame->pushInt( - c->load(types.address, types.i1, frame->popInt(), types.address)); + frame->pushInt(c->load(ir::SignExtend, + types.address, + types.i1, + frame->popInt(), + types.address)); } break; case i2c: { - frame->pushInt( - c->loadz(types.address, types.i2, frame->popInt(), types.address)); + frame->pushInt(c->load(ir::ZeroExtend, + types.address, + types.i2, + frame->popInt(), + types.address)); } break; case i2d: { @@ -4797,13 +4831,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2l: - frame->pushLong( - c->load(types.address, types.i4, frame->popInt(), types.i8)); + frame->pushLong(c->load( + ir::SignExtend, types.address, types.i4, frame->popInt(), types.i8)); break; case i2s: { - frame->pushInt( - c->load(types.address, types.i2, frame->popInt(), types.address)); + frame->pushInt(c->load(ir::SignExtend, + types.address, + types.i2, + frame->popInt(), + types.address)); } break; case iadd: @@ -5294,8 +5331,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case l2i: - frame->pushInt( - c->load(types.i8, types.i8, frame->popLong(), types.address)); + frame->pushInt(c->load( + ir::SignExtend, types.i8, types.i8, frame->popLong(), types.address)); break; case ladd: @@ -6149,7 +6186,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, normalizedKey); - c->jmp(c->load(types.address, + c->jmp(c->load(ir::SignExtend, + types.address, types.address, context->bootContext ? c->binaryOp(lir::Add, From 26d8e8aa1f48a66649b974d1a8136933166d91cb Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 11:43:10 -0600 Subject: [PATCH 26/89] add Compiler::truncateThenExtend --- include/avian/codegen/compiler.h | 5 +++++ src/codegen/compiler.cpp | 16 ++++++++++++++++ src/compile.cpp | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 8597d97604..3512d87847 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -107,6 +107,11 @@ class Compiler { virtual void checkBounds(Operand* object, unsigned lengthOffset, Operand* index, intptr_t handler) = 0; + virtual Operand* truncateThenExtend(ir::SignExtendMode signExtend, + ir::Type extendType, + ir::Type truncateType, + Operand* src) = 0; + virtual void store(ir::Type srcType, Operand* src, Operand* dst) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 307cbeb6cb..11a7b27b72 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2609,6 +2609,22 @@ class MyCompiler: public Compiler { static_cast(index), handler); } + virtual Operand* truncateThenExtend(ir::SignExtendMode signExtend, + ir::Type extendType, + ir::Type truncateType, + Operand* src) + { + Value* dst = value(&c, extendType); + appendMove(&c, + signExtend == ir::SignExtend ? lir::Move : lir::MoveZ, + TargetBytesPerWord, + truncateType.size(), + static_cast(src), + extendType.size(), + dst); + return dst; + } + virtual void store(ir::Type srcType, Operand* src, Operand* dst) diff --git a/src/compile.cpp b/src/compile.cpp index 05bd158c8c..3862635a11 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4831,8 +4831,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2l: - frame->pushLong(c->load( - ir::SignExtend, types.address, types.i4, frame->popInt(), types.i8)); + frame->pushLong(c->truncateThenExtend( + ir::SignExtend, types.i8, types.i4, frame->popInt())); break; case i2s: { From 4c4cc4951077de900d2ea6b8fc39043a7f25de5f Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 11:47:48 -0600 Subject: [PATCH 27/89] use Compiler::truncateThenExtend in more places --- src/codegen/compiler.cpp | 1 + src/compile.cpp | 21 ++++++--------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 11a7b27b72..cf1e2751a0 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2652,6 +2652,7 @@ class MyCompiler: public Compiler { assert(&c, dstType.size() >= TargetBytesPerWord); assert(&c, srcType.flavor() == srcSelectType.flavor()); assert(&c, srcType.flavor() == dstType.flavor()); + assert(&c, srcType == srcSelectType); Value* dst = value(&c, static_cast(src)->type); appendMove(&c, diff --git a/src/compile.cpp b/src/compile.cpp index 3862635a11..0a3e078aae 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4807,19 +4807,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2b: { - frame->pushInt(c->load(ir::SignExtend, - types.address, - types.i1, - frame->popInt(), - types.address)); + frame->pushInt(c->truncateThenExtend( + ir::SignExtend, types.address, types.i1, frame->popInt())); } break; case i2c: { - frame->pushInt(c->load(ir::ZeroExtend, - types.address, - types.i2, - frame->popInt(), - types.address)); + frame->pushInt(c->truncateThenExtend( + ir::ZeroExtend, types.address, types.i2, frame->popInt())); } break; case i2d: { @@ -4836,11 +4830,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case i2s: { - frame->pushInt(c->load(ir::SignExtend, - types.address, - types.i2, - frame->popInt(), - types.address)); + frame->pushInt(c->truncateThenExtend( + ir::SignExtend, types.address, types.i2, frame->popInt())); } break; case iadd: From 00253ce5280d42e57e437fc101063497fcb7ec0c Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 11:52:13 -0600 Subject: [PATCH 28/89] remove redundant Compiler::load srcSelectType parameter --- include/avian/codegen/compiler.h | 1 - src/codegen/compiler.cpp | 5 +---- src/compile.cpp | 28 ++-------------------------- 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 3512d87847..0775e46976 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -117,7 +117,6 @@ class Compiler { Operand* dst) = 0; virtual Operand* load(ir::SignExtendMode signExtend, ir::Type srcType, - ir::Type srcSelectType, Operand* src, ir::Type dstType) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index cf1e2751a0..348e100e8d 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2645,20 +2645,17 @@ class MyCompiler: public Compiler { virtual Operand* load(ir::SignExtendMode signExtend, ir::Type srcType, - ir::Type srcSelectType, Operand* src, ir::Type dstType) { assert(&c, dstType.size() >= TargetBytesPerWord); - assert(&c, srcType.flavor() == srcSelectType.flavor()); assert(&c, srcType.flavor() == dstType.flavor()); - assert(&c, srcType == srcSelectType); Value* dst = value(&c, static_cast(src)->type); appendMove(&c, signExtend == ir::SignExtend ? lir::Move : lir::MoveZ, srcType.size(), - srcSelectType.size(), + srcType.size(), static_cast(src), dstType.size(), dst); diff --git a/src/compile.cpp b/src/compile.cpp index 0a3e078aae..ca4c17ba8b 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3715,7 +3715,6 @@ popLongAddress(Frame* frame) ir::Types types(TargetBytesPerWord); return TargetBytesPerWord == 8 ? frame->popLong() : frame->c->load(ir::SignExtend, - types.i8, types.i8, frame->popLong(), types.address); @@ -3760,7 +3759,6 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* address = popLongAddress(frame); frame->popObject(); frame->pushInt(c->load(ir::SignExtend, - types.i1, types.i1, c->memory(address, types.i1), types.address)); @@ -3781,7 +3779,6 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* address = popLongAddress(frame); frame->popObject(); frame->pushInt(c->load(ir::SignExtend, - types.i2, types.i2, c->memory(address, types.i2), types.address)); @@ -3805,7 +3802,6 @@ intrinsic(MyThread* t, Frame* frame, object target) frame->popObject(); frame->pushInt( c->load(ir::SignExtend, - types.i4, types.i4, c->memory(address, MATCH(methodName(t, target), "getInt") ? types.i4 @@ -3833,7 +3829,6 @@ intrinsic(MyThread* t, Frame* frame, object target) frame->popObject(); frame->pushLong( c->load(ir::SignExtend, - types.i8, types.i8, c->memory(address, MATCH(methodName(t, target), "getLong") ? types.i8 @@ -3858,7 +3853,6 @@ intrinsic(MyThread* t, Frame* frame, object target) Compiler::Operand* address = popLongAddress(frame); frame->popObject(); frame->pushLong(c->load(ir::SignExtend, - types.address, types.address, c->memory(address, types.address), types.i8)); @@ -4114,7 +4108,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case aaload: frame->pushObject( c->load(ir::SignExtend, - types.address, types.address, c->memory(array, types.object, TargetArrayBody, index), types.address)); @@ -4123,7 +4116,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case faload: frame->pushInt( c->load(ir::SignExtend, - types.f4, types.f4, c->memory(array, types.f4, TargetArrayBody, index), types.f8)); @@ -4132,7 +4124,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case iaload: frame->pushInt( c->load(ir::SignExtend, - types.i4, types.i4, c->memory(array, types.i4, TargetArrayBody, index), types.address)); @@ -4141,7 +4132,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case baload: frame->pushInt( c->load(ir::SignExtend, - types.i1, types.i1, c->memory(array, types.i1, TargetArrayBody, index), types.address)); @@ -4150,7 +4140,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case caload: frame->pushInt( c->load(ir::ZeroExtend, - types.i2, types.i2, c->memory(array, types.i2, TargetArrayBody, index), types.address)); @@ -4159,7 +4148,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case daload: frame->pushLong( c->load(ir::SignExtend, - types.f8, types.f8, c->memory(array, types.f8, TargetArrayBody, index), types.f8)); @@ -4168,7 +4156,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case laload: frame->pushLong( c->load(ir::SignExtend, - types.i8, types.i8, c->memory(array, types.i8, TargetArrayBody, index), types.i8)); @@ -4177,7 +4164,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case saload: frame->pushInt( c->load(ir::SignExtend, - types.i2, types.i2, c->memory(array, types.i2, TargetArrayBody, index), types.address)); @@ -4337,7 +4323,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case arraylength: { frame->pushInt( c->load(ir::SignExtend, - types.address, types.address, c->memory(frame->popObject(), types.i4, TargetArrayLength), types.address)); @@ -4653,7 +4638,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( ir::SignExtend, types.i1, - types.i1, c->memory(table, types.i4, targetFieldOffset(context, field)), types.address)); break; @@ -4662,7 +4646,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( ir::ZeroExtend, types.i2, - types.i2, c->memory(table, types.i4, targetFieldOffset(context, field)), types.address)); break; @@ -4671,7 +4654,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( ir::SignExtend, types.i2, - types.i2, c->memory(table, types.i4, targetFieldOffset(context, field)), types.address)); break; @@ -4680,7 +4662,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( ir::SignExtend, types.f4, - types.f4, c->memory(table, types.f4, targetFieldOffset(context, field)), types.f8)); break; @@ -4689,7 +4670,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( ir::SignExtend, types.i4, - types.i4, c->memory(table, types.i4, targetFieldOffset(context, field)), types.address)); break; @@ -4698,7 +4678,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushLong(c->load( ir::SignExtend, types.f8, - types.f8, c->memory(table, types.f8, targetFieldOffset(context, field)), types.f8)); break; @@ -4707,7 +4686,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushLong(c->load( ir::SignExtend, types.i8, - types.i8, c->memory(table, types.i8, targetFieldOffset(context, field)), types.i8)); break; @@ -4716,7 +4694,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushObject(c->load( ir::SignExtend, types.address, - types.address, c->memory(table, types.object, targetFieldOffset(context, field)), types.address)); break; @@ -5322,8 +5299,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case l2i: - frame->pushInt(c->load( - ir::SignExtend, types.i8, types.i8, frame->popLong(), types.address)); + frame->pushInt( + c->load(ir::SignExtend, types.i8, frame->popLong(), types.address)); break; case ladd: @@ -6178,7 +6155,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, normalizedKey); c->jmp(c->load(ir::SignExtend, - types.address, types.address, context->bootContext ? c->binaryOp(lir::Add, From 42fec084b00662d9d9288f639765f6715ebe47ae Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 12:14:27 -0600 Subject: [PATCH 29/89] expose Value::type and add asserts --- include/avian/codegen/compiler.h | 12 ++++++-- src/codegen/compiler.cpp | 10 ++++-- src/codegen/compiler/value.cpp | 9 +++--- src/codegen/compiler/value.h | 1 - src/compile.cpp | 52 +++++++++++++++++++------------- 5 files changed, 54 insertions(+), 30 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 0775e46976..e35486bf01 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -40,7 +40,15 @@ class Compiler { static const unsigned TailJump = 1 << 2; static const unsigned LongJumpOrCall = 1 << 3; - class Operand { }; + class Operand { + public: + ir::Type type; + + Operand(ir::Type type) : type(type) + { + } + }; + class State { }; class Subroutine { }; @@ -121,7 +129,7 @@ class Compiler { ir::Type dstType) = 0; virtual void condJump(lir::TernaryOperation op, - unsigned size, + ir::Type type, Operand* a, Operand* b, Operand* address) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 348e100e8d..b89b7f6cbf 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2663,7 +2663,7 @@ class MyCompiler: public Compiler { } virtual void condJump(lir::TernaryOperation op, - unsigned size, + ir::Type type, Operand* a, Operand* b, Operand* address) @@ -2672,9 +2672,15 @@ class MyCompiler: public Compiler { (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or( isFloatBranch(op) and isFloatValue(a) and isFloatValue(b))); + // assert(&c, type.flavor() == static_cast(a)->type.flavor()); + // assert(&c, type.flavor() == static_cast(b)->type.flavor()); + assert(&c, + static_cast(address)->type + == ir::Type(ir::Type::Integer, TargetBytesPerWord)); + appendBranch(&c, op, - size, + type.size(), static_cast(a), static_cast(b), static_cast(address)); diff --git a/src/codegen/compiler/value.cpp b/src/codegen/compiler/value.cpp index 3fdccf23d6..c876ff9d4c 100644 --- a/src/codegen/compiler/value.cpp +++ b/src/codegen/compiler/value.cpp @@ -18,7 +18,8 @@ namespace codegen { namespace compiler { Value::Value(Site* site, Site* target, ir::Type type) - : reads(0), + : Compiler::Operand(type), + reads(0), lastRead(0), sites(site), source(0), @@ -26,9 +27,9 @@ Value::Value(Site* site, Site* target, ir::Type type) buddy(this), nextWord(this), home(NoFrameIndex), - wordIndex(0), - type(type) -{ } + wordIndex(0) +{ +} bool Value::findSite(Site* site) { for (Site* s = this->sites; s; s = s->next) { diff --git a/src/codegen/compiler/value.h b/src/codegen/compiler/value.h index 623042ce83..4efe689605 100644 --- a/src/codegen/compiler/value.h +++ b/src/codegen/compiler/value.h @@ -37,7 +37,6 @@ class Value: public Compiler::Operand { Value* nextWord; int16_t home; uint8_t wordIndex; - ir::Type type; Value(Site* site, Site* target, ir::Type type); diff --git a/src/compile.cpp b/src/compile.cpp index ca4c17ba8b..e208a6bb13 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1711,6 +1711,7 @@ class Frame { } void pushObject(Value o) { + // assert(t, o->type == types.object); pushQuiet(types.object, o); pushedObject(); } @@ -3595,10 +3596,14 @@ lir::TernaryOperation toCompilerJumpOp(MyThread* t, unsigned instruction) { } } -bool -integerBranch(MyThread* t, Frame* frame, object code, unsigned& ip, - unsigned size, Compiler::Operand* a, Compiler::Operand* b, - unsigned* newIpp) +bool integerBranch(MyThread* t, + Frame* frame, + object code, + unsigned& ip, + ir::Type type, + Compiler::Operand* a, + Compiler::Operand* b, + unsigned* newIpp) { if (ip + 3 > codeLength(t, code)) { return false; @@ -3619,7 +3624,7 @@ integerBranch(MyThread* t, Frame* frame, object code, unsigned& ip, case ifge: case iflt: case ifle: - c->condJump(toCompilerJumpOp(t, instruction), size, a, b, target); + c->condJump(toCompilerJumpOp(t, instruction), type, a, b, target); break; default: @@ -3669,10 +3674,15 @@ lir::TernaryOperation toCompilerFloatJumpOp(MyThread* t, } } -bool -floatBranch(MyThread* t, Frame* frame, object code, unsigned& ip, - unsigned size, bool lessIfUnordered, Compiler::Operand* a, - Compiler::Operand* b, unsigned* newIpp) +bool floatBranch(MyThread* t, + Frame* frame, + object code, + unsigned& ip, + ir::Type type, + bool lessIfUnordered, + Compiler::Operand* a, + Compiler::Operand* b, + unsigned* newIpp) { if (ip + 3 > codeLength(t, code)) { return false; @@ -3694,7 +3704,7 @@ floatBranch(MyThread* t, Frame* frame, object code, unsigned& ip, case iflt: case ifle: c->condJump(toCompilerFloatJumpOp(t, instruction, lessIfUnordered), - size, + type, a, b, target); @@ -4426,7 +4436,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popLong(); Compiler::Operand* b = frame->popLong(); - if (floatBranch(t, frame, code, ip, 8, false, a, b, &newIp)) { + if (floatBranch(t, frame, code, ip, types.f8, false, a, b, &newIp)) { goto branch; } else { frame->pushInt(c->call( @@ -4446,7 +4456,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popLong(); Compiler::Operand* b = frame->popLong(); - if (floatBranch(t, frame, code, ip, 8, true, a, b, &newIp)) { + if (floatBranch(t, frame, code, ip, types.f8, true, a, b, &newIp)) { goto branch; } else { frame->pushInt(c->call( @@ -4526,7 +4536,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popInt(); Compiler::Operand* b = frame->popInt(); - if (floatBranch(t, frame, code, ip, 4, false, a, b, &newIp)) { + if (floatBranch(t, frame, code, ip, types.f4, false, a, b, &newIp)) { goto branch; } else { frame->pushInt(c->call( @@ -4544,7 +4554,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popInt(); Compiler::Operand* b = frame->popInt(); - if (floatBranch(t, frame, code, ip, 4, true, a, b, &newIp)) { + if (floatBranch(t, frame, code, ip, types.f4, true, a, b, &newIp)) { goto branch; } else { frame->pushInt(c->call( @@ -4880,7 +4890,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* b = frame->popObject(); Compiler::Operand* target = frame->machineIp(newIp); - c->condJump(toCompilerJumpOp(t, instruction), TargetBytesPerWord, a, b, target); + c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target); } goto branch; case if_icmpeq: @@ -4901,7 +4911,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* b = frame->popInt(); Compiler::Operand* target = frame->machineIp(newIp); - c->condJump(toCompilerJumpOp(t, instruction), 4, a, b, target); + c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target); } goto branch; case ifeq: @@ -4923,7 +4933,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = c->constant(0, types.i4); Compiler::Operand* b = frame->popInt(); - c->condJump(toCompilerJumpOp(t, instruction), 4, a, b, target); + c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target); } goto branch; case ifnull: @@ -4940,7 +4950,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* b = frame->popObject(); Compiler::Operand* target = frame->machineIp(newIp); - c->condJump(toCompilerJumpOp(t, instruction), TargetBytesPerWord, a, b, target); + c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target); } goto branch; case iinc: { @@ -5319,7 +5329,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = frame->popLong(); Compiler::Operand* b = frame->popLong(); - if (integerBranch(t, frame, code, ip, 8, a, b, &newIp)) { + if (integerBranch(t, frame, code, ip, types.i8, a, b, &newIp)) { goto branch; } else { frame->pushInt( @@ -6029,7 +6039,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* key = frame->popInt(); c->condJump(lir::JumpIfLess, - 4, + types.i4, c->constant(bottom, types.i4), key, frame->machineIp(defaultIp)); @@ -6123,7 +6133,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->restoreState(s->state); c->condJump(lir::JumpIfGreater, - 4, + types.i4, c->constant(s->top, types.i4), s->key, frame->machineIp(s->defaultIp)); From 865041b6884cb1a9fabce723d72b2eddc2586c37 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 12:37:01 -0600 Subject: [PATCH 30/89] add asserts --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 14 ++++++++++---- src/compile.cpp | 14 +++++++------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index e35486bf01..e83e00a9f0 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -73,7 +73,7 @@ class Compiler { virtual Operand* constant(int64_t value, ir::Type type) = 0; virtual Operand* promiseConstant(Promise* value, ir::Type type) = 0; - virtual Operand* address(Promise* address) = 0; + virtual Operand* address(ir::Type type, Promise* address) = 0; virtual Operand* memory(Operand* base, ir::Type type, int displacement = 0, diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index b89b7f6cbf..86a3ffea29 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -1252,6 +1252,13 @@ Value* loadLocal(Context* c, ir::Type type, unsigned index) fprintf(stderr, "load local %p at %d\n", c->locals[index].value, index); } + assert(c, + type.flavor() != ir::Type::Object + || c->locals[index].value->type.flavor() == ir::Type::Object + // TODO: this is a very java-specific hole in the type system. Get + // rid of it: + || c->locals[index].value->type.flavor() == ir::Type::Address); + return c->locals[index].value; } @@ -2311,10 +2318,9 @@ class MyCompiler: public Compiler { return compiler::value(&c, type, compiler::constantSite(&c, value)); } - virtual Operand* address(Promise* address) { - return value(&c, - ir::Type(ir::Type::Address, TargetBytesPerWord), - compiler::addressSite(&c, address)); + virtual Operand* address(ir::Type type, Promise* address) + { + return value(&c, type, compiler::addressSite(&c, address)); } virtual Operand* memory(Operand* base, diff --git a/src/compile.cpp b/src/compile.cpp index e208a6bb13..071664717d 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1414,14 +1414,14 @@ class Frame { return c->binaryOp( lir::Add, - types.address, + types.object, c->memory( - c->threadRegister(), types.address, TARGET_THREAD_HEAPIMAGE), - c->promiseConstant(p, types.address)); + c->threadRegister(), types.object, TARGET_THREAD_HEAPIMAGE), + c->promiseConstant(p, types.object)); } else { for (PoolElement* e = context->objectPool; e; e = e->next) { if (o == e->target) { - return c->address(e); + return c->address(types.object, e); } } @@ -1429,7 +1429,7 @@ class Frame { ++ context->objectPoolCount; - return c->address(context->objectPool); + return c->address(types.object, context->objectPool); } } @@ -1711,7 +1711,7 @@ class Frame { } void pushObject(Value o) { - // assert(t, o->type == types.object); + assert(t, o->type == types.object || o->type.flavor() == ir::Type::Address); pushQuiet(types.object, o); pushedObject(); } @@ -3130,7 +3130,7 @@ ir::Type operandTypeForFieldCode(Thread* t, unsigned code) return types.i8; case ObjectField: - return types.address; + return types.object; case FloatField: return types.f4; From 479c056b2cd7ece5dfdd030d9588a9428e6c3bd6 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 12:44:42 -0600 Subject: [PATCH 31/89] move Compiler::Operand to ir::Value --- include/avian/codegen/compiler.h | 122 +++++---- include/avian/codegen/ir.h | 9 + src/codegen/compiler.cpp | 115 +++++---- src/codegen/compiler/value.cpp | 2 +- src/codegen/compiler/value.h | 6 +- src/compile.cpp | 425 ++++++++++++++++--------------- 6 files changed, 351 insertions(+), 328 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index e83e00a9f0..a86b8cb309 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -40,15 +40,6 @@ class Compiler { static const unsigned TailJump = 1 << 2; static const unsigned LongJumpOrCall = 1 << 3; - class Operand { - public: - ir::Type type; - - Operand(ir::Type type) : type(type) - { - } - }; - class State { }; class Subroutine { }; @@ -56,8 +47,8 @@ class Compiler { virtual void restoreState(State* state) = 0; virtual Subroutine* startSubroutine() = 0; - virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address) - = 0; + virtual void returnFromSubroutine(Subroutine* subroutine, ir::Value* address) + = 0; virtual void linkSubroutine(Subroutine* subroutine) = 0; virtual void init(unsigned logicalCodeSize, unsigned parameterFootprint, @@ -71,83 +62,84 @@ class Compiler { virtual Promise* poolAppend(intptr_t value) = 0; virtual Promise* poolAppendPromise(Promise* value) = 0; - virtual Operand* constant(int64_t value, ir::Type type) = 0; - virtual Operand* promiseConstant(Promise* value, ir::Type type) = 0; - virtual Operand* address(ir::Type type, Promise* address) = 0; - virtual Operand* memory(Operand* base, - ir::Type type, - int displacement = 0, - Operand* index = 0) = 0; + virtual ir::Value* constant(int64_t value, ir::Type type) = 0; + virtual ir::Value* promiseConstant(Promise* value, ir::Type type) = 0; + virtual ir::Value* address(ir::Type type, Promise* address) = 0; + virtual ir::Value* memory(ir::Value* base, + ir::Type type, + int displacement = 0, + ir::Value* index = 0) = 0; - virtual Operand* threadRegister() = 0; + virtual ir::Value* threadRegister() = 0; - virtual void push(ir::Type type, Operand* value) = 0; - virtual void save(ir::Type type, Operand* value) = 0; - virtual Operand* pop(ir::Type type) = 0; + virtual void push(ir::Type type, ir::Value* value) = 0; + virtual void save(ir::Type type, ir::Value* value) = 0; + virtual ir::Value* pop(ir::Type type) = 0; virtual void pushed() = 0; virtual void popped(unsigned footprint) = 0; virtual unsigned topOfStack() = 0; - virtual Operand* peek(unsigned footprint, unsigned index) = 0; + virtual ir::Value* peek(unsigned footprint, unsigned index) = 0; - virtual Operand* call(Operand* address, - unsigned flags, - TraceHandler* traceHandler, - ir::Type resultType, - unsigned argumentCount, - ...) = 0; + virtual ir::Value* call(ir::Value* address, + unsigned flags, + TraceHandler* traceHandler, + ir::Type resultType, + unsigned argumentCount, + ...) = 0; - virtual Operand* stackCall(Operand* address, - unsigned flags, - TraceHandler* traceHandler, - ir::Type resultType, - unsigned argumentFootprint) = 0; + virtual ir::Value* stackCall(ir::Value* address, + unsigned flags, + TraceHandler* traceHandler, + ir::Type resultType, + unsigned argumentFootprint) = 0; - virtual void return_(ir::Type type, Operand* value) = 0; + virtual void return_(ir::Type type, ir::Value* value) = 0; virtual void return_() = 0; virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0; virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0; - virtual void storeLocal(unsigned footprint, Operand* src, - unsigned index) = 0; - virtual Operand* loadLocal(ir::Type type, unsigned index) = 0; + virtual void storeLocal(unsigned footprint, ir::Value* src, unsigned index) + = 0; + virtual ir::Value* loadLocal(ir::Type type, unsigned index) = 0; virtual void saveLocals() = 0; - virtual void checkBounds(Operand* object, unsigned lengthOffset, - Operand* index, intptr_t handler) = 0; + virtual void checkBounds(ir::Value* object, + unsigned lengthOffset, + ir::Value* index, + intptr_t handler) = 0; - virtual Operand* truncateThenExtend(ir::SignExtendMode signExtend, - ir::Type extendType, - ir::Type truncateType, - Operand* src) = 0; + virtual ir::Value* truncateThenExtend(ir::SignExtendMode signExtend, + ir::Type extendType, + ir::Type truncateType, + ir::Value* src) = 0; - virtual void store(ir::Type srcType, - Operand* src, - Operand* dst) = 0; - virtual Operand* load(ir::SignExtendMode signExtend, - ir::Type srcType, - Operand* src, - ir::Type dstType) = 0; + virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) = 0; + virtual ir::Value* load(ir::SignExtendMode signExtend, + ir::Type srcType, + ir::Value* src, + ir::Type dstType) = 0; virtual void condJump(lir::TernaryOperation op, ir::Type type, - Operand* a, - Operand* b, - Operand* address) = 0; + ir::Value* a, + ir::Value* b, + ir::Value* address) = 0; - virtual void jmp(Operand* address) = 0; - virtual void exit(Operand* address) = 0; + virtual void jmp(ir::Value* address) = 0; + virtual void exit(ir::Value* address) = 0; - virtual Operand* binaryOp(lir::TernaryOperation op, - ir::Type type, - Operand* a, - Operand* b) = 0; - virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a) - = 0; + virtual ir::Value* binaryOp(lir::TernaryOperation op, + ir::Type type, + ir::Value* a, + ir::Value* b) = 0; + virtual ir::Value* unaryOp(lir::BinaryOperation op, + ir::Type type, + ir::Value* a) = 0; virtual void nullaryOp(lir::Operation op) = 0; - virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) = 0; - virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) = 0; - virtual Operand* i2f(ir::Type aType, ir::Type resType, Operand* a) = 0; + virtual ir::Value* f2f(ir::Type aType, ir::Type resType, ir::Value* a) = 0; + virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a) = 0; + virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a) = 0; virtual void compile(uintptr_t stackOverflowHandler, unsigned stackLimitOffset) = 0; diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h index e1870f8e57..9c84e0c782 100644 --- a/include/avian/codegen/ir.h +++ b/include/avian/codegen/ir.h @@ -115,6 +115,15 @@ class Types { enum SignExtendMode { SignExtend, ZeroExtend }; +class Value { + public: + ir::Type type; + + Value(ir::Type type) : type(type) + { + } +}; + } // namespace ir } // namespace codegen } // namespace avian diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 86a3ffea29..6b05fed086 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2151,7 +2151,8 @@ class MyCompiler: public Compiler { return c.subroutine = new(c.zone) MySubroutine; } - virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address) { + virtual void returnFromSubroutine(Subroutine* subroutine, ir::Value* address) + { appendSaveLocals(&c); appendJump(&c, lir::Jump, static_cast(address), false, true); static_cast(subroutine)->forkState = compiler::saveState(&c); @@ -2308,25 +2309,25 @@ class MyCompiler: public Compiler { return p; } - virtual Operand* constant(int64_t value, ir::Type type) + virtual ir::Value* constant(int64_t value, ir::Type type) { return promiseConstant(resolvedPromise(&c, value), type); } - virtual Operand* promiseConstant(Promise* value, ir::Type type) + virtual ir::Value* promiseConstant(Promise* value, ir::Type type) { return compiler::value(&c, type, compiler::constantSite(&c, value)); } - virtual Operand* address(ir::Type type, Promise* address) + virtual ir::Value* address(ir::Type type, Promise* address) { return value(&c, type, compiler::addressSite(&c, address)); } - virtual Operand* memory(Operand* base, - ir::Type type, - int displacement = 0, - Operand* index = 0) + virtual ir::Value* memory(ir::Value* base, + ir::Type type, + int displacement = 0, + ir::Value* index = 0) { Value* result = value(&c, type); @@ -2340,7 +2341,7 @@ class MyCompiler: public Compiler { return result; } - virtual Operand* threadRegister() + virtual ir::Value* threadRegister() { return compiler::threadRegister(&c); } @@ -2349,7 +2350,7 @@ class MyCompiler: public Compiler { return c.logicalCode[c.logicalIp]->lastEvent->makeCodePromise(&c); } - virtual void push(ir::Type type, Operand* value) + virtual void push(ir::Type type, ir::Value* value) { // TODO: once type information is flowed properly, enable this assert. // Some time later, we can remove the parameter. @@ -2357,7 +2358,7 @@ class MyCompiler: public Compiler { compiler::push(&c, typeFootprint(&c, type), static_cast(value)); } - virtual void save(ir::Type type, Operand* value) + virtual void save(ir::Type type, ir::Value* value) { // TODO: once type information is flowed properly, enable this assert. // Some time later, we can remove the parameter. @@ -2373,9 +2374,9 @@ class MyCompiler: public Compiler { } } - virtual Operand* pop(ir::Type type) + virtual ir::Value* pop(ir::Type type) { - Operand* value = compiler::pop(&c, typeFootprint(&c, type)); + ir::Value* value = compiler::pop(&c, typeFootprint(&c, type)); // TODO: once type information is flowed properly, enable this assert. // Some time later, we can remove the parameter. // assert(&c, static_cast(value)->type == type); @@ -2409,7 +2410,8 @@ class MyCompiler: public Compiler { return c.stack->index; } - virtual Operand* peek(unsigned footprint, unsigned index) { + virtual ir::Value* peek(unsigned footprint, unsigned index) + { Stack* s = c.stack; for (unsigned i = index; i > 0; --i) { s = s->next; @@ -2445,12 +2447,12 @@ class MyCompiler: public Compiler { return s->value; } - virtual Operand* call(Operand* address, - unsigned flags, - TraceHandler* traceHandler, - ir::Type resultType, - unsigned argumentCount, - ...) + virtual ir::Value* call(ir::Value* address, + unsigned flags, + TraceHandler* traceHandler, + ir::Type resultType, + unsigned argumentCount, + ...) { va_list a; va_start(a, argumentCount); @@ -2500,11 +2502,11 @@ class MyCompiler: public Compiler { return result; } - virtual Operand* stackCall(Operand* address, - unsigned flags, - TraceHandler* traceHandler, - ir::Type resultType, - unsigned argumentFootprint) + virtual ir::Value* stackCall(ir::Value* address, + unsigned flags, + TraceHandler* traceHandler, + ir::Type resultType, + unsigned argumentFootprint) { Value* result = value(&c, resultType); appendCall(&c, @@ -2519,7 +2521,7 @@ class MyCompiler: public Compiler { return result; } - virtual void return_(ir::Type type, Operand* value) + virtual void return_(ir::Type type, ir::Value* value) { // TODO: once type information is flowed properly, enable this assert. // Some time later, we can remove the parameter. @@ -2595,11 +2597,12 @@ class MyCompiler: public Compiler { linkLocals(&c, e->locals(), newLocals); } - virtual void storeLocal(unsigned footprint, Operand* src, unsigned index) { + virtual void storeLocal(unsigned footprint, ir::Value* src, unsigned index) + { compiler::storeLocal(&c, footprint, static_cast(src), index, true); } - virtual Operand* loadLocal(ir::Type type, unsigned index) + virtual ir::Value* loadLocal(ir::Type type, unsigned index) { return compiler::loadLocal(&c, type, index); } @@ -2608,17 +2611,19 @@ class MyCompiler: public Compiler { appendSaveLocals(&c); } - virtual void checkBounds(Operand* object, unsigned lengthOffset, - Operand* index, intptr_t handler) + virtual void checkBounds(ir::Value* object, + unsigned lengthOffset, + ir::Value* index, + intptr_t handler) { appendBoundsCheck(&c, static_cast(object), lengthOffset, static_cast(index), handler); } - virtual Operand* truncateThenExtend(ir::SignExtendMode signExtend, - ir::Type extendType, - ir::Type truncateType, - Operand* src) + virtual ir::Value* truncateThenExtend(ir::SignExtendMode signExtend, + ir::Type extendType, + ir::Type truncateType, + ir::Value* src) { Value* dst = value(&c, extendType); appendMove(&c, @@ -2631,9 +2636,7 @@ class MyCompiler: public Compiler { return dst; } - virtual void store(ir::Type srcType, - Operand* src, - Operand* dst) + virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) { assert(&c, srcType.flavor() == static_cast(src)->type.flavor()); assert(&c, srcType.flavor() == static_cast(dst)->type.flavor()); @@ -2649,10 +2652,10 @@ class MyCompiler: public Compiler { static_cast(dst)); } - virtual Operand* load(ir::SignExtendMode signExtend, - ir::Type srcType, - Operand* src, - ir::Type dstType) + virtual ir::Value* load(ir::SignExtendMode signExtend, + ir::Type srcType, + ir::Value* src, + ir::Type dstType) { assert(&c, dstType.size() >= TargetBytesPerWord); assert(&c, srcType.flavor() == dstType.flavor()); @@ -2670,9 +2673,9 @@ class MyCompiler: public Compiler { virtual void condJump(lir::TernaryOperation op, ir::Type type, - Operand* a, - Operand* b, - Operand* address) + ir::Value* a, + ir::Value* b, + ir::Value* address) { assert(&c, (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or( @@ -2692,18 +2695,20 @@ class MyCompiler: public Compiler { static_cast(address)); } - virtual void jmp(Operand* address) { + virtual void jmp(ir::Value* address) + { appendJump(&c, lir::Jump, static_cast(address)); } - virtual void exit(Operand* address) { + virtual void exit(ir::Value* address) + { appendJump(&c, lir::Jump, static_cast(address), true); } - virtual Operand* binaryOp(lir::TernaryOperation op, - ir::Type type, - Operand* a, - Operand* b) + virtual ir::Value* binaryOp(lir::TernaryOperation op, + ir::Type type, + ir::Value* a, + ir::Value* b) { assert(&c, (isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b)) @@ -2722,7 +2727,9 @@ class MyCompiler: public Compiler { return result; } - virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a) + virtual ir::Value* unaryOp(lir::BinaryOperation op, + ir::Type type, + ir::Value* a) { assert(&c, (isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op) @@ -2733,7 +2740,7 @@ class MyCompiler: public Compiler { return result; } - virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) + virtual ir::Value* f2f(ir::Type aType, ir::Type resType, ir::Value* a) { assert(&c, aType == static_cast(a)->type); assert(&c, isFloatValue(a)); @@ -2749,7 +2756,7 @@ class MyCompiler: public Compiler { return result; } - virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) + virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a) { // TODO: enable when possible // assert(&c, aType == static_cast(a)->type); @@ -2766,7 +2773,7 @@ class MyCompiler: public Compiler { return result; } - virtual Operand* i2f(ir::Type aType, ir::Type resType, Operand* a) + virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a) { // TODO: enable when possible // assert(&c, aType == static_cast(a)->type); diff --git a/src/codegen/compiler/value.cpp b/src/codegen/compiler/value.cpp index c876ff9d4c..d04d2c6e0a 100644 --- a/src/codegen/compiler/value.cpp +++ b/src/codegen/compiler/value.cpp @@ -18,7 +18,7 @@ namespace codegen { namespace compiler { Value::Value(Site* site, Site* target, ir::Type type) - : Compiler::Operand(type), + : ir::Value(type), reads(0), lastRead(0), sites(site), diff --git a/src/codegen/compiler/value.h b/src/codegen/compiler/value.h index 4efe689605..3eaed04fa7 100644 --- a/src/codegen/compiler/value.h +++ b/src/codegen/compiler/value.h @@ -26,7 +26,7 @@ const int NoFrameIndex = -1; const bool DebugSites = false; -class Value: public Compiler::Operand { +class Value : public ir::Value { public: Read* reads; Read* lastRead; @@ -66,12 +66,12 @@ class Value: public Compiler::Operand { }; -inline bool isFloatValue(Compiler::Operand* a) +inline bool isFloatValue(ir::Value* a) { return static_cast(a)->type.flavor() == ir::Type::Float; } -inline bool isGeneralValue(Compiler::Operand* a) +inline bool isGeneralValue(ir::Value* a) { return !isFloatValue(a); } diff --git a/src/compile.cpp b/src/compile.cpp index 071664717d..6d156e9083 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1331,18 +1331,19 @@ translateLocalIndex(Context* context, unsigned footprint, unsigned index) } } -Compiler::Operand* loadLocal(Context* context, - unsigned footprint, - ir::Type type, - unsigned index) +ir::Value* loadLocal(Context* context, + unsigned footprint, + ir::Type type, + unsigned index) { return context->compiler->loadLocal( type, translateLocalIndex(context, footprint, index)); } -void -storeLocal(Context* context, unsigned footprint, Compiler::Operand* value, - unsigned index) +void storeLocal(Context* context, + unsigned footprint, + ir::Value* value, + unsigned index) { context->compiler->storeLocal (footprint, value, translateLocalIndex(context, footprint, index)); @@ -1358,8 +1359,6 @@ class Frame { Object }; - typedef Compiler::Operand* Value; - Frame(Context* context, uint8_t* stackMap) : context(context), t(context->thread), @@ -1399,11 +1398,12 @@ class Frame { void dispose() { if (level > 1) { - context->eventLog.append(PopContextEvent); + context->eventLog.append(PopContextEvent); } } - Value append(object o) { + ir::Value* append(object o) + { BootContext* bc = context->bootContext; if (bc) { avian::codegen::Promise* p = new (bc->zone) avian::codegen::ListenPromise(t->m->system, bc->zone); @@ -1637,11 +1637,13 @@ class Frame { } } - Value addressOperand(avian::codegen::Promise* p) { + ir::Value* addressOperand(avian::codegen::Promise* p) + { return c->promiseConstant(p, types.address); } - Value absoluteAddressOperand(avian::codegen::Promise* p) { + ir::Value* absoluteAddressOperand(avian::codegen::Promise* p) + { return context->bootContext ? c->binaryOp( lir::Add, @@ -1658,7 +1660,8 @@ class Frame { : addressOperand(p); } - Value machineIp(unsigned logicalIp) { + ir::Value* machineIp(unsigned logicalIp) + { return c->promiseConstant(c->machineIp(logicalIp), types.address); } @@ -1682,35 +1685,40 @@ class Frame { this->ip = ip; } - void pushQuiet(ir::Type type, Value o) + void pushQuiet(ir::Type type, ir::Value* o) { c->push(type, o); } - void pushLongQuiet(Value o) { + void pushLongQuiet(ir::Value* o) + { pushQuiet(types.i8, o); } - Value popQuiet(ir::Type type) + ir::Value* popQuiet(ir::Type type) { return c->pop(type); } - Value popLongQuiet() { + ir::Value* popLongQuiet() + { return popQuiet(types.i8); } - void pushInt(Value o) { + void pushInt(ir::Value* o) + { pushQuiet(types.i4, o); pushedInt(); } - void pushAddress(Value o) { + void pushAddress(ir::Value* o) + { pushQuiet(types.i4, o); pushedInt(); } - void pushObject(Value o) { + void pushObject(ir::Value* o) + { assert(t, o->type == types.object || o->type.flavor() == ir::Type::Address); pushQuiet(types.object, o); pushedObject(); @@ -1722,7 +1730,8 @@ class Frame { pushedObject(); } - void pushLong(Value o) { + void pushLong(ir::Value* o) + { pushLongQuiet(o); pushedLong(); } @@ -1732,17 +1741,20 @@ class Frame { c->popped(count); } - Value popInt() { + ir::Value* popInt() + { poppedInt(); return popQuiet(types.i4); } - Value popLong() { + ir::Value* popLong() + { poppedLong(); return popLongQuiet(); } - - Value popObject() { + + ir::Value* popObject() + { poppedObject(); return popQuiet(types.object); } @@ -1798,8 +1810,8 @@ class Frame { } void dupX1() { - Value s0 = popQuiet(types.i4); - Value s1 = popQuiet(types.i4); + ir::Value* s0 = popQuiet(types.i4); + ir::Value* s1 = popQuiet(types.i4); pushQuiet(types.i4, s0); pushQuiet(types.i4, s1); @@ -1809,17 +1821,17 @@ class Frame { } void dupX2() { - Value s0 = popQuiet(types.i4); + ir::Value* s0 = popQuiet(types.i4); if (get(sp - 2) == Long) { - Value s1 = popLongQuiet(); + ir::Value* s1 = popLongQuiet(); pushQuiet(types.i4, s0); pushLongQuiet(s1); pushQuiet(types.i4, s0); } else { - Value s1 = popQuiet(types.i4); - Value s2 = popQuiet(types.i4); + ir::Value* s1 = popQuiet(types.i4); + ir::Value* s2 = popQuiet(types.i4); pushQuiet(types.i4, s0); pushQuiet(types.i4, s2); @@ -1834,8 +1846,8 @@ class Frame { if (get(sp - 1) == Long) { pushLongQuiet(c->peek(2, 0)); } else { - Value s0 = popQuiet(types.i4); - Value s1 = popQuiet(types.i4); + ir::Value* s0 = popQuiet(types.i4); + ir::Value* s1 = popQuiet(types.i4); pushQuiet(types.i4, s1); pushQuiet(types.i4, s0); @@ -1848,16 +1860,16 @@ class Frame { void dup2X1() { if (get(sp - 1) == Long) { - Value s0 = popLongQuiet(); - Value s1 = popQuiet(types.i4); + ir::Value* s0 = popLongQuiet(); + ir::Value* s1 = popQuiet(types.i4); pushLongQuiet(s0); pushQuiet(types.i4, s1); pushLongQuiet(s0); } else { - Value s0 = popQuiet(types.i4); - Value s1 = popQuiet(types.i4); - Value s2 = popQuiet(types.i4); + ir::Value* s0 = popQuiet(types.i4); + ir::Value* s1 = popQuiet(types.i4); + ir::Value* s2 = popQuiet(types.i4); pushQuiet(types.i4, s1); pushQuiet(types.i4, s0); @@ -1871,17 +1883,17 @@ class Frame { void dup2X2() { if (get(sp - 1) == Long) { - Value s0 = popLongQuiet(); + ir::Value* s0 = popLongQuiet(); if (get(sp - 3) == Long) { - Value s1 = popLongQuiet(); + ir::Value* s1 = popLongQuiet(); pushLongQuiet(s0); pushLongQuiet(s1); pushLongQuiet(s0); } else { - Value s1 = popQuiet(types.i4); - Value s2 = popQuiet(types.i4); + ir::Value* s1 = popQuiet(types.i4); + ir::Value* s2 = popQuiet(types.i4); pushLongQuiet(s0); pushQuiet(types.i4, s2); @@ -1889,10 +1901,10 @@ class Frame { pushLongQuiet(s0); } } else { - Value s0 = popQuiet(types.i4); - Value s1 = popQuiet(types.i4); - Value s2 = popQuiet(types.i4); - Value s3 = popQuiet(types.i4); + ir::Value* s0 = popQuiet(types.i4); + ir::Value* s1 = popQuiet(types.i4); + ir::Value* s2 = popQuiet(types.i4); + ir::Value* s3 = popQuiet(types.i4); pushQuiet(types.i4, s1); pushQuiet(types.i4, s0); @@ -1906,8 +1918,8 @@ class Frame { } void swap() { - Value s0 = popQuiet(types.i4); - Value s1 = popQuiet(types.i4); + ir::Value* s0 = popQuiet(types.i4); + ir::Value* s1 = popQuiet(types.i4); pushQuiet(types.i4, s0); pushQuiet(types.i4, s1); @@ -3065,9 +3077,10 @@ resultSize(MyThread* t, unsigned code) } } -void -pushReturnValue(MyThread* t, Frame* frame, unsigned code, - Compiler::Operand* result) +void pushReturnValue(MyThread* t, + Frame* frame, + unsigned code, + ir::Value* result) { switch (code) { case ByteField: @@ -3090,8 +3103,7 @@ pushReturnValue(MyThread* t, Frame* frame, unsigned code, } } -Compiler::Operand* -popField(MyThread* t, Frame* frame, int code) +ir::Value* popField(MyThread* t, Frame* frame, int code) { switch (code) { case ByteField: @@ -3169,12 +3181,12 @@ void compileSafePoint(MyThread* t, Compiler* c, Frame* frame) { c->threadRegister()); } -Compiler::Operand* compileDirectInvoke(MyThread* t, - Frame* frame, - object target, - bool tailCall, - bool useThunk, - avian::codegen::Promise* addressPromise) +ir::Value* compileDirectInvoke(MyThread* t, + Frame* frame, + object target, + bool tailCall, + bool useThunk, + avian::codegen::Promise* addressPromise) { avian::codegen::Compiler* c = frame->c; ir::Types types(TargetBytesPerWord); @@ -3205,7 +3217,7 @@ Compiler::Operand* compileDirectInvoke(MyThread* t, (frame->context->zone.allocate(sizeof(TraceElementPromise))) TraceElementPromise(t->m->system, trace); - Compiler::Operand* result = c->stackCall( + ir::Value* result = c->stackCall( c->promiseConstant(returnAddressPromise, types.address), flags, trace, @@ -3233,7 +3245,7 @@ Compiler::Operand* compileDirectInvoke(MyThread* t, methodParameterFootprint(t, target)); } } else { - Compiler::Operand* address + ir::Value* address = (addressPromise ? c->promiseConstant(addressPromise, types.address) : c->constant(methodAddress(t, target), types.address)); @@ -3253,7 +3265,7 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall) { unsigned rSize = resultSize(t, methodReturnCode(t, target)); - Compiler::Operand* result = 0; + ir::Value* result = 0; // don't bother calling an empty method unless calling it might // cause the class to be initialized, which may have side effects @@ -3319,9 +3331,12 @@ methodReferenceReturnCode(Thread* t, object reference) return returnCode; } -void -compileReferenceInvoke(MyThread* t, Frame* frame, Compiler::Operand* method, - object reference, bool isStatic, bool tailCall) +void compileReferenceInvoke(MyThread* t, + Frame* frame, + ir::Value* method, + object reference, + bool isStatic, + bool tailCall) { unsigned parameterFootprint = methodReferenceParameterFootprint(t, reference, isStatic); @@ -3330,12 +3345,12 @@ compileReferenceInvoke(MyThread* t, Frame* frame, Compiler::Operand* method, unsigned rSize = resultSize(t, returnCode); - Compiler::Operand* result = frame->c->stackCall - (method, - tailCall ? Compiler::TailJump : 0, - frame->trace(0, 0), - operandTypeForFieldCode(t, returnCode), - parameterFootprint); + ir::Value* result + = frame->c->stackCall(method, + tailCall ? Compiler::TailJump : 0, + frame->trace(0, 0), + operandTypeForFieldCode(t, returnCode), + parameterFootprint); frame->pop(parameterFootprint); @@ -3369,9 +3384,11 @@ compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk, tailCall); } -void -compileAbstractInvoke(MyThread* t, Frame* frame, Compiler::Operand* method, - object target, bool tailCall) +void compileAbstractInvoke(MyThread* t, + Frame* frame, + ir::Value* method, + object target, + bool tailCall) { unsigned parameterFootprint = methodParameterFootprint(t, target); ir::Types types(TargetBytesPerWord); @@ -3380,12 +3397,12 @@ compileAbstractInvoke(MyThread* t, Frame* frame, Compiler::Operand* method, unsigned rSize = resultSize(t, returnCode); - Compiler::Operand* result = frame->c->stackCall - (method, - tailCall ? Compiler::TailJump : 0, - frame->trace(0, 0), - operandTypeForFieldCode(t, returnCode), - parameterFootprint); + ir::Value* result + = frame->c->stackCall(method, + tailCall ? Compiler::TailJump : 0, + frame->trace(0, 0), + operandTypeForFieldCode(t, returnCode), + parameterFootprint); frame->pop(parameterFootprint); @@ -3422,7 +3439,7 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) object method = frame->context->method; if (methodFlags(t, method) & ACC_SYNCHRONIZED) { - Compiler::Operand* lock; + ir::Value* lock; if (methodFlags(t, method) & ACC_STATIC) { PROTECT(t, method); @@ -3601,8 +3618,8 @@ bool integerBranch(MyThread* t, object code, unsigned& ip, ir::Type type, - Compiler::Operand* a, - Compiler::Operand* b, + ir::Value* a, + ir::Value* b, unsigned* newIpp) { if (ip + 3 > codeLength(t, code)) { @@ -3614,8 +3631,8 @@ bool integerBranch(MyThread* t, uint32_t offset = codeReadInt16(t, code, ip); uint32_t newIp = (ip - 3) + offset; assert(t, newIp < codeLength(t, code)); - - Compiler::Operand* target = frame->machineIp(newIp); + + ir::Value* target = frame->machineIp(newIp); switch (instruction) { case ifeq: @@ -3680,8 +3697,8 @@ bool floatBranch(MyThread* t, unsigned& ip, ir::Type type, bool lessIfUnordered, - Compiler::Operand* a, - Compiler::Operand* b, + ir::Value* a, + ir::Value* b, unsigned* newIpp) { if (ip + 3 > codeLength(t, code)) { @@ -3693,8 +3710,8 @@ bool floatBranch(MyThread* t, uint32_t offset = codeReadInt16(t, code, ip); uint32_t newIp = (ip - 3) + offset; assert(t, newIp < codeLength(t, code)); - - Compiler::Operand* target = frame->machineIp(newIp); + + ir::Value* target = frame->machineIp(newIp); switch (instruction) { case ifeq: @@ -3719,8 +3736,7 @@ bool floatBranch(MyThread* t, return true; } -Compiler::Operand* -popLongAddress(Frame* frame) +ir::Value* popLongAddress(Frame* frame) { ir::Types types(TargetBytesPerWord); return TargetBytesPerWord == 8 ? frame->popLong() @@ -3766,7 +3782,7 @@ intrinsic(MyThread* t, Frame* frame, object target) if (MATCH(methodName(t, target), "getByte") and MATCH(methodSpec(t, target), "(J)B")) { - Compiler::Operand* address = popLongAddress(frame); + ir::Value* address = popLongAddress(frame); frame->popObject(); frame->pushInt(c->load(ir::SignExtend, types.i1, @@ -3776,8 +3792,8 @@ intrinsic(MyThread* t, Frame* frame, object target) } else if (MATCH(methodName(t, target), "putByte") and MATCH(methodSpec(t, target), "(JB)V")) { - Compiler::Operand* value = frame->popInt(); - Compiler::Operand* address = popLongAddress(frame); + ir::Value* value = frame->popInt(); + ir::Value* address = popLongAddress(frame); frame->popObject(); c->store(types.address, value, c->memory(address, types.i1)); return true; @@ -3786,7 +3802,7 @@ intrinsic(MyThread* t, Frame* frame, object target) or (MATCH(methodName(t, target), "getChar") and MATCH(methodSpec(t, target), "(J)C"))) { - Compiler::Operand* address = popLongAddress(frame); + ir::Value* address = popLongAddress(frame); frame->popObject(); frame->pushInt(c->load(ir::SignExtend, types.i2, @@ -3798,8 +3814,8 @@ intrinsic(MyThread* t, Frame* frame, object target) or (MATCH(methodName(t, target), "putChar") and MATCH(methodSpec(t, target), "(JC)V"))) { - Compiler::Operand* value = frame->popInt(); - Compiler::Operand* address = popLongAddress(frame); + ir::Value* value = frame->popInt(); + ir::Value* address = popLongAddress(frame); frame->popObject(); c->store(types.address, value, c->memory(address, types.i2)); return true; @@ -3808,7 +3824,7 @@ intrinsic(MyThread* t, Frame* frame, object target) or (MATCH(methodName(t, target), "getFloat") and MATCH(methodSpec(t, target), "(J)F"))) { - Compiler::Operand* address = popLongAddress(frame); + ir::Value* address = popLongAddress(frame); frame->popObject(); frame->pushInt( c->load(ir::SignExtend, @@ -3823,8 +3839,8 @@ intrinsic(MyThread* t, Frame* frame, object target) or (MATCH(methodName(t, target), "putFloat") and MATCH(methodSpec(t, target), "(JF)V"))) { - Compiler::Operand* value = frame->popInt(); - Compiler::Operand* address = popLongAddress(frame); + ir::Value* value = frame->popInt(); + ir::Value* address = popLongAddress(frame); frame->popObject(); ir::Type type = MATCH(methodName(t, target), "putInt") ? types.i4 : types.f4; @@ -3835,7 +3851,7 @@ intrinsic(MyThread* t, Frame* frame, object target) or (MATCH(methodName(t, target), "getDouble") and MATCH(methodSpec(t, target), "(J)D"))) { - Compiler::Operand* address = popLongAddress(frame); + ir::Value* address = popLongAddress(frame); frame->popObject(); frame->pushLong( c->load(ir::SignExtend, @@ -3850,8 +3866,8 @@ intrinsic(MyThread* t, Frame* frame, object target) or (MATCH(methodName(t, target), "putDouble") and MATCH(methodSpec(t, target), "(JD)V"))) { - Compiler::Operand* value = frame->popLong(); - Compiler::Operand* address = popLongAddress(frame); + ir::Value* value = frame->popLong(); + ir::Value* address = popLongAddress(frame); frame->popObject(); ir::Type type = MATCH(methodName(t, target), "putLong") ? types.i8 : types.f8; @@ -3860,7 +3876,7 @@ intrinsic(MyThread* t, Frame* frame, object target) } else if (MATCH(methodName(t, target), "getAddress") and MATCH(methodSpec(t, target), "(J)J")) { - Compiler::Operand* address = popLongAddress(frame); + ir::Value* address = popLongAddress(frame); frame->popObject(); frame->pushLong(c->load(ir::SignExtend, types.address, @@ -3870,8 +3886,8 @@ intrinsic(MyThread* t, Frame* frame, object target) } else if (MATCH(methodName(t, target), "putAddress") and MATCH(methodSpec(t, target), "(JJ)V")) { - Compiler::Operand* value = frame->popLong(); - Compiler::Operand* address = popLongAddress(frame); + ir::Value* value = frame->popLong(); + ir::Value* address = popLongAddress(frame); frame->popObject(); c->store(types.i8, value, c->memory(address, types.address)); return true; @@ -3949,18 +3965,18 @@ class SwitchState { SwitchState(Compiler::State* state, unsigned count, unsigned defaultIp, - Compiler::Operand* key, + ir::Value* key, avian::codegen::Promise* start, int bottom, - int top): - state(state), - count(count), - defaultIp(defaultIp), - key(key), - start(start), - bottom(bottom), - top(top), - index(0) + int top) + : state(state), + count(count), + defaultIp(defaultIp), + key(key), + start(start), + bottom(bottom), + top(top), + index(0) { } Frame* frame() { @@ -3976,7 +3992,7 @@ class SwitchState { Compiler::State* state; unsigned count; unsigned defaultIp; - Compiler::Operand* key; + ir::Value* key; avian::codegen::Promise* start; int bottom; int top; @@ -4102,8 +4118,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case iaload: case laload: case saload: { - Compiler::Operand* index = frame->popInt(); - Compiler::Operand* array = frame->popObject(); + ir::Value* index = frame->popInt(); + ir::Value* array = frame->popObject(); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); @@ -4189,7 +4205,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case iastore: case lastore: case sastore: { - Compiler::Operand* value; + ir::Value* value; if (instruction == dastore or instruction == lastore) { value = frame->popLong(); } else if (instruction == aastore) { @@ -4198,8 +4214,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, value = frame->popInt(); } - Compiler::Operand* index = frame->popInt(); - Compiler::Operand* array = frame->popObject(); + ir::Value* index = frame->popInt(); + ir::Value* array = frame->popObject(); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); @@ -4303,7 +4319,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, object class_ = resolveClassInPool(t, context->method, index - 1, false); - Compiler::Operand* length = frame->popInt(); + ir::Value* length = frame->popInt(); object argument; Thunk thunk; @@ -4359,7 +4375,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case athrow: { - Compiler::Operand* target = frame->popObject(); + ir::Value* target = frame->popObject(); c->call(c->constant(getThunk(t, throw_Thunk), types.address), Compiler::NoReturn, frame->trace(0, 0), @@ -4396,7 +4412,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, thunk = checkCastFromReferenceThunk; } - Compiler::Operand* instance = c->peek(1, 0); + ir::Value* instance = c->peek(1, 0); c->call(c->constant(getThunk(t, thunk), types.address), 0, @@ -4425,16 +4441,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case dmul: case ddiv: case vm::drem: { - Compiler::Operand* a = frame->popLong(); - Compiler::Operand* b = frame->popLong(); + ir::Value* a = frame->popLong(); + ir::Value* b = frame->popLong(); frame->pushLong( c->binaryOp(toCompilerBinaryOp(t, instruction), types.f8, a, b)); } break; case dcmpg: { - Compiler::Operand* a = frame->popLong(); - Compiler::Operand* b = frame->popLong(); + ir::Value* a = frame->popLong(); + ir::Value* b = frame->popLong(); if (floatBranch(t, frame, code, ip, types.f8, false, a, b, &newIp)) { goto branch; @@ -4445,16 +4461,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.i4, 4, - static_cast(0), + static_cast(0), a, - static_cast(0), + static_cast(0), b)); } } break; case dcmpl: { - Compiler::Operand* a = frame->popLong(); - Compiler::Operand* b = frame->popLong(); + ir::Value* a = frame->popLong(); + ir::Value* b = frame->popLong(); if (floatBranch(t, frame, code, ip, types.f8, true, a, b, &newIp)) { goto branch; @@ -4465,9 +4481,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.i4, 4, - static_cast(0), + static_cast(0), a, - static_cast(0), + static_cast(0), b)); } } break; @@ -4525,16 +4541,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case fmul: case fdiv: case frem: { - Compiler::Operand* a = frame->popInt(); - Compiler::Operand* b = frame->popInt(); + ir::Value* a = frame->popInt(); + ir::Value* b = frame->popInt(); frame->pushInt( c->binaryOp(toCompilerBinaryOp(t, instruction), types.f4, a, b)); } break; case fcmpg: { - Compiler::Operand* a = frame->popInt(); - Compiler::Operand* b = frame->popInt(); + ir::Value* a = frame->popInt(); + ir::Value* b = frame->popInt(); if (floatBranch(t, frame, code, ip, types.f4, false, a, b, &newIp)) { goto branch; @@ -4551,8 +4567,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case fcmpl: { - Compiler::Operand* a = frame->popInt(); - Compiler::Operand* b = frame->popInt(); + ir::Value* a = frame->popInt(); + ir::Value* b = frame->popInt(); if (floatBranch(t, frame, code, ip, types.f4, true, a, b, &newIp)) { goto branch; @@ -4613,7 +4629,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->append(field)); } - Compiler::Operand* table; + ir::Value* table; if (instruction == getstatic) { checkField(t, field, true); @@ -4737,7 +4753,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Type rType = operandTypeForFieldCode(t, fieldCode); - Compiler::Operand* result; + ir::Value* result; if (instruction == getstatic) { result = c->call( c->constant(getThunk(t, getStaticFieldValueFromReferenceThunk), @@ -4749,7 +4765,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->threadRegister(), frame->append(pair)); } else { - Compiler::Operand* instance = frame->popObject(); + ir::Value* instance = frame->popObject(); result = c->call( c->constant(getThunk(t, getFieldValueFromReferenceThunk), @@ -4830,8 +4846,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case isub: case ixor: case imul: { - Compiler::Operand* a = frame->popInt(); - Compiler::Operand* b = frame->popInt(); + ir::Value* a = frame->popInt(); + ir::Value* b = frame->popInt(); frame->pushInt( c->binaryOp(toCompilerBinaryOp(t, instruction), types.i4, a, b)); } break; @@ -4865,8 +4881,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case idiv: { - Compiler::Operand* a = frame->popInt(); - Compiler::Operand* b = frame->popInt(); + ir::Value* a = frame->popInt(); + ir::Value* b = frame->popInt(); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); @@ -4885,10 +4901,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if(newIp <= ip) { compileSafePoint(t, c, frame); } - - Compiler::Operand* a = frame->popObject(); - Compiler::Operand* b = frame->popObject(); - Compiler::Operand* target = frame->machineIp(newIp); + + ir::Value* a = frame->popObject(); + ir::Value* b = frame->popObject(); + ir::Value* target = frame->machineIp(newIp); c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target); } goto branch; @@ -4906,10 +4922,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if(newIp <= ip) { compileSafePoint(t, c, frame); } - - Compiler::Operand* a = frame->popInt(); - Compiler::Operand* b = frame->popInt(); - Compiler::Operand* target = frame->machineIp(newIp); + + ir::Value* a = frame->popInt(); + ir::Value* b = frame->popInt(); + ir::Value* target = frame->machineIp(newIp); c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target); } goto branch; @@ -4924,14 +4940,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, newIp = (ip - 3) + offset; assert(t, newIp < codeLength(t, code)); - Compiler::Operand* target = frame->machineIp(newIp); + ir::Value* target = frame->machineIp(newIp); if(newIp <= ip) { compileSafePoint(t, c, frame); } - Compiler::Operand* a = c->constant(0, types.i4); - Compiler::Operand* b = frame->popInt(); + ir::Value* a = c->constant(0, types.i4); + ir::Value* b = frame->popInt(); c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target); } goto branch; @@ -4946,9 +4962,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - Compiler::Operand* a = c->constant(0, types.object); - Compiler::Operand* b = frame->popObject(); - Compiler::Operand* target = frame->machineIp(newIp); + ir::Value* a = c->constant(0, types.object); + ir::Value* b = frame->popObject(); + ir::Value* target = frame->machineIp(newIp); c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target); } goto branch; @@ -5005,7 +5021,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, object class_ = resolveClassInPool(t, context->method, index - 1, false); - Compiler::Operand* instance = frame->popObject(); + ir::Value* instance = frame->popObject(); object argument; Thunk thunk; @@ -5065,7 +5081,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, unsigned rSize = resultSize(t, returnCode); - Compiler::Operand* result + ir::Value* result = c->stackCall(c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), @@ -5171,11 +5187,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, unsigned offset = TargetClassVtable + (methodOffset(t, target) * TargetBytesPerWord); - Compiler::Operand* instance = c->peek(1, parameterFootprint - 1); + ir::Value* instance = c->peek(1, parameterFootprint - 1); unsigned rSize = resultSize(t, methodReturnCode(t, target)); - Compiler::Operand* result = c->stackCall( + ir::Value* result = c->stackCall( c->memory(c->binaryOp(lir::And, types.address, c->constant(TargetPointerMask, types.i4), @@ -5227,8 +5243,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case irem: { - Compiler::Operand* a = frame->popInt(); - Compiler::Operand* b = frame->popInt(); + ir::Value* a = frame->popInt(); + ir::Value* b = frame->popInt(); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); @@ -5319,15 +5335,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lsub: case lxor: case lmul: { - Compiler::Operand* a = frame->popLong(); - Compiler::Operand* b = frame->popLong(); + ir::Value* a = frame->popLong(); + ir::Value* b = frame->popLong(); frame->pushLong( c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b)); } break; case lcmp: { - Compiler::Operand* a = frame->popLong(); - Compiler::Operand* b = frame->popLong(); + ir::Value* a = frame->popLong(); + ir::Value* b = frame->popLong(); if (integerBranch(t, frame, code, ip, types.i8, a, b, &newIp)) { goto branch; @@ -5338,9 +5354,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 0, types.i4, 4, - static_cast(0), + static_cast(0), a, - static_cast(0), + static_cast(0), b)); } } break; @@ -5425,8 +5441,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case ldiv_: { - Compiler::Operand* a = frame->popLong(); - Compiler::Operand* b = frame->popLong(); + ir::Value* a = frame->popLong(); + ir::Value* b = frame->popLong(); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); @@ -5470,16 +5486,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ip = (ip + 3) & ~3; // pad to four byte boundary - Compiler::Operand* key = frame->popInt(); - + ir::Value* key = frame->popInt(); + uint32_t defaultIp = base + codeReadInt32(t, code, ip); assert(t, defaultIp < codeLength(t, code)); int32_t pairCount = codeReadInt32(t, code, ip); if (pairCount) { - Compiler::Operand* default_ = frame->addressOperand - (frame->addressPromise(c->machineIp(defaultIp))); + ir::Value* default_ = frame->addressOperand( + frame->addressPromise(c->machineIp(defaultIp))); avian::codegen::Promise* start = 0; uint32_t* ipTable = static_cast @@ -5501,7 +5517,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } assert(t, start); - Compiler::Operand* address = c->call( + ir::Value* address = c->call( c->constant(getThunk(t, lookUpAddressThunk), types.address), 0, 0, @@ -5533,8 +5549,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lrem: { - Compiler::Operand* a = frame->popLong(); - Compiler::Operand* b = frame->popLong(); + ir::Value* a = frame->popLong(); + ir::Value* b = frame->popLong(); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); @@ -5558,8 +5574,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lshl: case lshr: case lushr: { - Compiler::Operand* a = frame->popInt(); - Compiler::Operand* b = frame->popLong(); + ir::Value* a = frame->popInt(); + ir::Value* b = frame->popLong(); frame->pushLong( c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b)); } break; @@ -5590,7 +5606,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case monitorenter: { - Compiler::Operand* target = frame->popObject(); + ir::Value* target = frame->popObject(); c->call( c->constant(getThunk(t, acquireMonitorForObjectThunk), types.address), 0, @@ -5602,7 +5618,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case monitorexit: { - Compiler::Operand* target = frame->popObject(); + ir::Value* target = frame->popObject(); c->call( c->constant(getThunk(t, releaseMonitorForObjectThunk), types.address), 0, @@ -5639,7 +5655,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, (t, localSize(t, context->method) + c->topOfStack(), context->method) + t->arch->frameReturnAddressSize(); - Compiler::Operand* result + ir::Value* result = c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), @@ -5690,7 +5706,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case newarray: { uint8_t type = codeBody(t, code, ip++); - Compiler::Operand* length = frame->popInt(); + ir::Value* length = frame->popInt(); frame->pushObject( c->call(c->constant(getThunk(t, makeBlankArrayThunk), types.address), @@ -5773,9 +5789,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } } - Compiler::Operand* value = popField(t, frame, fieldCode); + ir::Value* value = popField(t, frame, fieldCode); - Compiler::Operand* table; + ir::Value* table; if (instruction == putstatic) { PROTECT(t, field); @@ -5877,7 +5893,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, int fieldCode = vm::fieldCode (t, byteArrayBody(t, referenceSpec(t, reference), 0)); - Compiler::Operand* value = popField(t, frame, fieldCode); + ir::Value* value = popField(t, frame, fieldCode); ir::Type rType = operandTypeForFieldCode(t, fieldCode); object pair = makePair(t, context->method, reference); @@ -5901,7 +5917,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->append(pair), value); } else { - Compiler::Operand* instance = frame->popObject(); + ir::Value* instance = frame->popObject(); c->call(c->constant(getThunk(t, setFieldValueFromReferenceThunk), types.address), @@ -5928,10 +5944,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 4, c->threadRegister(), frame->append(pair), - static_cast(0), + static_cast(0), value); } else { - Compiler::Operand* instance = frame->popObject(); + ir::Value* instance = frame->popObject(); c->call( c->constant(getThunk(t, setLongFieldValueFromReferenceThunk), @@ -5943,7 +5959,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->threadRegister(), frame->append(pair), instance, - static_cast(0), + static_cast(0), value); } } break; @@ -5962,7 +5978,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->append(pair), value); } else { - Compiler::Operand* instance = frame->popObject(); + ir::Value* instance = frame->popObject(); c->call( c->constant(getThunk(t, setObjectFieldValueFromReferenceThunk), @@ -6036,7 +6052,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } assert(t, start); - Compiler::Operand* key = frame->popInt(); + ir::Value* key = frame->popInt(); c->condJump(lir::JumpIfLess, types.i4, @@ -6151,18 +6167,17 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->restoreState(s->state); - Compiler::Operand* normalizedKey + ir::Value* normalizedKey = (s->bottom ? c->binaryOp(lir::Subtract, types.i4, c->constant(s->bottom, types.i4), s->key) : s->key); - Compiler::Operand* entry - = c->memory(frame->absoluteAddressOperand(s->start), - types.address, - 0, - normalizedKey); + ir::Value* entry = c->memory(frame->absoluteAddressOperand(s->start), + types.address, + 0, + normalizedKey); c->jmp(c->load(ir::SignExtend, types.address, From 86a98240b4940605f7b7ac860a9b89ba8cb568c6 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 12:47:38 -0600 Subject: [PATCH 32/89] remove useless static_casts to retrieve ir::Value::type --- src/codegen/compiler.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 6b05fed086..f631c72f6d 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2354,7 +2354,7 @@ class MyCompiler: public Compiler { { // TODO: once type information is flowed properly, enable this assert. // Some time later, we can remove the parameter. - // assert(&c, static_cast(value)->type == type); + // assert(&c, value->type == type); compiler::push(&c, typeFootprint(&c, type), static_cast(value)); } @@ -2362,7 +2362,7 @@ class MyCompiler: public Compiler { { // TODO: once type information is flowed properly, enable this assert. // Some time later, we can remove the parameter. - // assert(&c, static_cast(value)->type == type); + // assert(&c, value->type == type); unsigned footprint = typeFootprint(&c, type); c.saved = cons(&c, static_cast(value), c.saved); if (TargetBytesPerWord == 4 and footprint > 1) { @@ -2638,17 +2638,17 @@ class MyCompiler: public Compiler { virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) { - assert(&c, srcType.flavor() == static_cast(src)->type.flavor()); - assert(&c, srcType.flavor() == static_cast(dst)->type.flavor()); + assert(&c, srcType.flavor() == src->type.flavor()); + assert(&c, srcType.flavor() == dst->type.flavor()); assert(&c, - srcType.flavor() != ir::Type::Float - || srcType.size() == static_cast(src)->type.size()); + srcType.flavor() != ir::Type::Float || srcType.size() + == src->type.size()); appendMove(&c, lir::Move, srcType.size(), srcType.size(), static_cast(src), - static_cast(dst)->type.size(), + dst->type.size(), static_cast(dst)); } @@ -2660,7 +2660,7 @@ class MyCompiler: public Compiler { assert(&c, dstType.size() >= TargetBytesPerWord); assert(&c, srcType.flavor() == dstType.flavor()); - Value* dst = value(&c, static_cast(src)->type); + Value* dst = value(&c, src->type); appendMove(&c, signExtend == ir::SignExtend ? lir::Move : lir::MoveZ, srcType.size(), @@ -2681,11 +2681,10 @@ class MyCompiler: public Compiler { (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or( isFloatBranch(op) and isFloatValue(a) and isFloatValue(b))); - // assert(&c, type.flavor() == static_cast(a)->type.flavor()); - // assert(&c, type.flavor() == static_cast(b)->type.flavor()); + // assert(&c, type.flavor() == a->type.flavor()); + // assert(&c, type.flavor() == b->type.flavor()); assert(&c, - static_cast(address)->type - == ir::Type(ir::Type::Integer, TargetBytesPerWord)); + address->type == ir::Type(ir::Type::Integer, TargetBytesPerWord)); appendBranch(&c, op, @@ -2714,7 +2713,7 @@ class MyCompiler: public Compiler { (isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b)) or(isFloatBinaryOp(op) and isFloatValue(a) and isFloatValue(b))); - Value* result = value(&c, static_cast(a)->type); + Value* result = value(&c, a->type); appendCombine(&c, op, @@ -2734,7 +2733,7 @@ class MyCompiler: public Compiler { assert(&c, (isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op) and isFloatValue(a))); - Value* result = value(&c, static_cast(a)->type); + Value* result = value(&c, a->type); appendTranslate( &c, op, type.size(), static_cast(a), type.size(), result); return result; @@ -2742,7 +2741,7 @@ class MyCompiler: public Compiler { virtual ir::Value* f2f(ir::Type aType, ir::Type resType, ir::Value* a) { - assert(&c, aType == static_cast(a)->type); + assert(&c, aType == a->type); assert(&c, isFloatValue(a)); assert(&c, resType.flavor() == ir::Type::Float); assert(&c, aType.flavor() == ir::Type::Float); @@ -2759,7 +2758,7 @@ class MyCompiler: public Compiler { virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a) { // TODO: enable when possible - // assert(&c, aType == static_cast(a)->type); + // assert(&c, aType == a->type); assert(&c, isFloatValue(a)); assert(&c, resType.flavor() != ir::Type::Float); assert(&c, aType.flavor() == ir::Type::Float); @@ -2776,7 +2775,7 @@ class MyCompiler: public Compiler { virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a) { // TODO: enable when possible - // assert(&c, aType == static_cast(a)->type); + // assert(&c, aType == a->type); assert(&c, isGeneralValue(a)); assert(&c, resType.flavor() == ir::Type::Float); assert(&c, aType.flavor() != ir::Type::Float); From ad3ec1abf3e704d38aa0bcc844b86923810684a9 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 13:56:39 -0600 Subject: [PATCH 33/89] introduce Frame::stackCall util --- include/avian/codegen/compiler.h | 3 +- src/compile.cpp | 125 ++++++++++++++++--------------- 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index a86b8cb309..31d0535082 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -91,7 +91,8 @@ class Compiler { unsigned flags, TraceHandler* traceHandler, ir::Type resultType, - unsigned argumentFootprint) = 0; + unsigned argumentFootprint /*, + util::Slice arguments*/) = 0; virtual void return_(ir::Type type, ir::Value* value) = 0; virtual void return_() = 0; diff --git a/src/compile.cpp b/src/compile.cpp index 6d156e9083..b89ea7aaf5 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1351,6 +1351,38 @@ void storeLocal(Context* context, avian::util::FixedAllocator* codeAllocator(MyThread* t); +ir::Type operandTypeForFieldCode(Thread* t, unsigned code) +{ + ir::Types types(TargetBytesPerWord); + + switch (code) { + case ByteField: + case BooleanField: + return types.i1; + case CharField: + case ShortField: + return types.i2; + case IntField: + return types.i4; + case LongField: + return types.i8; + + case ObjectField: + return types.object; + + case FloatField: + return types.f4; + case DoubleField: + return types.f8; + + case VoidField: + return types.void_; + + default: + abort(t); + } +} + class Frame { public: enum StackType { @@ -1942,6 +1974,21 @@ class Frame { return e; } + ir::Value* stackCall(ir::Value* methodValue, + object methodObject, + unsigned flags, + TraceElement* trace) + { + ir::Value* result = c->stackCall( + methodValue, + flags, + trace, + operandTypeForFieldCode(t, methodReturnCode(t, methodObject)), + methodParameterFootprint(t, methodObject)); + + return result; + } + unsigned startSubroutine(unsigned ip, avian::codegen::Promise* returnAddress) { pushAddress(absoluteAddressOperand(returnAddress)); @@ -3125,38 +3172,6 @@ ir::Value* popField(MyThread* t, Frame* frame, int code) } } -ir::Type operandTypeForFieldCode(Thread* t, unsigned code) -{ - ir::Types types(TargetBytesPerWord); - - switch (code) { - case ByteField: - case BooleanField: - return types.i1; - case CharField: - case ShortField: - return types.i2; - case IntField: - return types.i4; - case LongField: - return types.i8; - - case ObjectField: - return types.object; - - case FloatField: - return types.f4; - case DoubleField: - return types.f8; - - case VoidField: - return types.void_; - - default: - abort(t); - } -} - bool useLongJump(MyThread* t, uintptr_t target) { @@ -3217,12 +3232,11 @@ ir::Value* compileDirectInvoke(MyThread* t, (frame->context->zone.allocate(sizeof(TraceElementPromise))) TraceElementPromise(t->m->system, trace); - ir::Value* result = c->stackCall( + ir::Value* result = frame->stackCall( c->promiseConstant(returnAddressPromise, types.address), + target, flags, - trace, - operandTypeForFieldCode(t, methodReturnCode(t, target)), - methodParameterFootprint(t, target)); + trace); c->store( types.address, @@ -3237,12 +3251,10 @@ ir::Value* compileDirectInvoke(MyThread* t, return result; } else { - return c->stackCall( - c->constant(defaultThunk(t), types.address), - flags, - frame->trace(target, traceFlags), - operandTypeForFieldCode(t, methodReturnCode(t, target)), - methodParameterFootprint(t, target)); + return frame->stackCall(c->constant(defaultThunk(t), types.address), + target, + flags, + frame->trace(target, traceFlags)); } } else { ir::Value* address @@ -3250,13 +3262,13 @@ ir::Value* compileDirectInvoke(MyThread* t, ? c->promiseConstant(addressPromise, types.address) : c->constant(methodAddress(t, target), types.address)); - return c->stackCall - (address, - flags, - tailCall ? 0 : frame->trace - ((methodFlags(t, target) & ACC_NATIVE) ? target : 0, 0), - operandTypeForFieldCode(t, methodReturnCode(t, target)), - methodParameterFootprint(t, target)); + return frame->stackCall( + address, + target, + flags, + tailCall ? 0 + : frame->trace( + (methodFlags(t, target) & ACC_NATIVE) ? target : 0, 0)); } } @@ -3397,12 +3409,8 @@ void compileAbstractInvoke(MyThread* t, unsigned rSize = resultSize(t, returnCode); - ir::Value* result - = frame->c->stackCall(method, - tailCall ? Compiler::TailJump : 0, - frame->trace(0, 0), - operandTypeForFieldCode(t, returnCode), - parameterFootprint); + ir::Value* result = frame->stackCall( + method, target, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0)); frame->pop(parameterFootprint); @@ -5191,17 +5199,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, unsigned rSize = resultSize(t, methodReturnCode(t, target)); - ir::Value* result = c->stackCall( + ir::Value* result = frame->stackCall( c->memory(c->binaryOp(lir::And, types.address, c->constant(TargetPointerMask, types.i4), c->memory(instance, types.object)), types.object, offset), + target, tailCall ? Compiler::TailJump : 0, - frame->trace(0, 0), - operandTypeForFieldCode(t, methodReturnCode(t, target)), - parameterFootprint); + frame->trace(0, 0)); frame->pop(parameterFootprint); From 3aa85f24945374c434dbd89fe2d75855a0b89447 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 14:21:42 -0600 Subject: [PATCH 34/89] move return handling into Frame::stackCall --- src/compile.cpp | 157 +++++++++++++++++++----------------------------- 1 file changed, 62 insertions(+), 95 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index b89ea7aaf5..5932bae742 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1974,19 +1974,47 @@ class Frame { return e; } - ir::Value* stackCall(ir::Value* methodValue, - object methodObject, - unsigned flags, - TraceElement* trace) + void pushReturnValue(unsigned code, ir::Value* result) { - ir::Value* result = c->stackCall( - methodValue, - flags, - trace, - operandTypeForFieldCode(t, methodReturnCode(t, methodObject)), - methodParameterFootprint(t, methodObject)); + switch (code) { + case ByteField: + case BooleanField: + case CharField: + case ShortField: + case FloatField: + case IntField: + return pushInt(result); - return result; + case ObjectField: + return pushObject(result); + + case LongField: + case DoubleField: + return pushLong(result); + + default: + abort(t); + } + } + + void stackCall(ir::Value* methodValue, + object methodObject, + unsigned flags, + TraceElement* trace) + { + unsigned footprint = methodParameterFootprint(t, methodObject); + unsigned returnCode = methodReturnCode(t, methodObject); + ir::Value* result = c->stackCall(methodValue, + flags, + trace, + operandTypeForFieldCode(t, returnCode), + footprint); + + pop(footprint); + + if (returnCode != VoidField) { + pushReturnValue(returnCode, result); + } } unsigned startSubroutine(unsigned ip, avian::codegen::Promise* returnAddress) { @@ -3124,32 +3152,6 @@ resultSize(MyThread* t, unsigned code) } } -void pushReturnValue(MyThread* t, - Frame* frame, - unsigned code, - ir::Value* result) -{ - switch (code) { - case ByteField: - case BooleanField: - case CharField: - case ShortField: - case FloatField: - case IntField: - return frame->pushInt(result); - - case ObjectField: - return frame->pushObject(result); - - case LongField: - case DoubleField: - return frame->pushLong(result); - - default: - abort(t); - } -} - ir::Value* popField(MyThread* t, Frame* frame, int code) { switch (code) { @@ -3196,12 +3198,12 @@ void compileSafePoint(MyThread* t, Compiler* c, Frame* frame) { c->threadRegister()); } -ir::Value* compileDirectInvoke(MyThread* t, - Frame* frame, - object target, - bool tailCall, - bool useThunk, - avian::codegen::Promise* addressPromise) +void compileDirectInvoke(MyThread* t, + Frame* frame, + object target, + bool tailCall, + bool useThunk, + avian::codegen::Promise* addressPromise) { avian::codegen::Compiler* c = frame->c; ir::Types types(TargetBytesPerWord); @@ -3232,11 +3234,10 @@ ir::Value* compileDirectInvoke(MyThread* t, (frame->context->zone.allocate(sizeof(TraceElementPromise))) TraceElementPromise(t->m->system, trace); - ir::Value* result = frame->stackCall( - c->promiseConstant(returnAddressPromise, types.address), - target, - flags, - trace); + frame->stackCall(c->promiseConstant(returnAddressPromise, types.address), + target, + flags, + trace); c->store( types.address, @@ -3248,8 +3249,6 @@ ir::Value* compileDirectInvoke(MyThread* t, ? nativeThunk(t) : defaultThunk(t), types.address)); - - return result; } else { return frame->stackCall(c->constant(defaultThunk(t), types.address), target, @@ -3262,7 +3261,7 @@ ir::Value* compileDirectInvoke(MyThread* t, ? c->promiseConstant(addressPromise, types.address) : c->constant(methodAddress(t, target), types.address)); - return frame->stackCall( + frame->stackCall( address, target, flags, @@ -3275,15 +3274,12 @@ ir::Value* compileDirectInvoke(MyThread* t, bool compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall) { - unsigned rSize = resultSize(t, methodReturnCode(t, target)); - - ir::Value* result = 0; - // don't bother calling an empty method unless calling it might // cause the class to be initialized, which may have side effects if (emptyMethod(t, target) and (not classNeedsInit(t, methodClass(t, target)))) { + frame->pop(methodParameterFootprint(t, target)); tailCall = false; } else { BootContext* bc = frame->context->bootContext; @@ -3299,25 +3295,19 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall) object pointer = makePointer(t, p); bc->calls = makeTriple(t, target, pointer, bc->calls); - result = compileDirectInvoke(t, frame, target, tailCall, false, p); + compileDirectInvoke(t, frame, target, tailCall, false, p); } else { - result = compileDirectInvoke(t, frame, target, tailCall, true, 0); + compileDirectInvoke(t, frame, target, tailCall, true, 0); } } else if (unresolved(t, methodAddress(t, target)) or classNeedsInit(t, methodClass(t, target))) { - result = compileDirectInvoke(t, frame, target, tailCall, true, 0); + compileDirectInvoke(t, frame, target, tailCall, true, 0); } else { - result = compileDirectInvoke(t, frame, target, tailCall, false, 0); + compileDirectInvoke(t, frame, target, tailCall, false, 0); } } - frame->pop(methodParameterFootprint(t, target)); - - if (rSize) { - pushReturnValue(t, frame, methodReturnCode(t, target), result); - } - return tailCall; } @@ -3367,7 +3357,7 @@ void compileReferenceInvoke(MyThread* t, frame->pop(parameterFootprint); if (rSize) { - pushReturnValue(t, frame, returnCode, result); + frame->pushReturnValue(returnCode, result); } } @@ -3396,27 +3386,13 @@ compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk, tailCall); } -void compileAbstractInvoke(MyThread* t, - Frame* frame, +void compileAbstractInvoke(Frame* frame, ir::Value* method, object target, bool tailCall) { - unsigned parameterFootprint = methodParameterFootprint(t, target); - ir::Types types(TargetBytesPerWord); - - int returnCode = methodReturnCode(t, target); - - unsigned rSize = resultSize(t, returnCode); - - ir::Value* result = frame->stackCall( + frame->stackCall( method, target, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0)); - - frame->pop(parameterFootprint); - - if (rSize) { - pushReturnValue(t, frame, returnCode, result); - } } void @@ -3426,8 +3402,7 @@ compileDirectAbstractInvoke(MyThread* t, Frame* frame, Thunk thunk, avian::codegen::Compiler* c = frame->c; ir::Types types(TargetBytesPerWord); - compileAbstractInvoke(t, - frame, + compileAbstractInvoke(frame, c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), @@ -4787,7 +4762,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, instance); } - pushReturnValue(t, frame, fieldCode, result); + frame->pushReturnValue(fieldCode, result); } } break; @@ -5106,7 +5081,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pop(parameterFootprint); if (rSize) { - pushReturnValue(t, frame, returnCode, result); + frame->pushReturnValue(returnCode, result); } } break; @@ -5197,9 +5172,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* instance = c->peek(1, parameterFootprint - 1); - unsigned rSize = resultSize(t, methodReturnCode(t, target)); - - ir::Value* result = frame->stackCall( + frame->stackCall( c->memory(c->binaryOp(lir::And, types.address, c->constant(TargetPointerMask, types.i4), @@ -5209,12 +5182,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, target, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0)); - - frame->pop(parameterFootprint); - - if (rSize) { - pushReturnValue(t, frame, methodReturnCode(t, target), result); - } } else { // OpenJDK generates invokevirtual calls to private methods // (e.g. readObject and writeObject for serialization), so From 4e00a1e3042e630a46fb6a4b466e5ed8349eacbf Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 14:30:45 -0600 Subject: [PATCH 35/89] add Frame::referenceStackCall --- src/compile.cpp | 100 ++++++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 5932bae742..e1a9ac3436 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1383,6 +1383,33 @@ ir::Type operandTypeForFieldCode(Thread* t, unsigned code) } } +unsigned methodReferenceParameterFootprint(Thread* t, + object reference, + bool isStatic) +{ + return parameterFootprint( + t, + reinterpret_cast( + &byteArrayBody(t, referenceSpec(t, reference), 0)), + isStatic); +} + +int methodReferenceReturnCode(Thread* t, object reference) +{ + unsigned parameterCount; + unsigned parameterFootprint; + unsigned returnCode; + scanMethodSpec(t, + reinterpret_cast( + &byteArrayBody(t, referenceSpec(t, reference), 0)), + true, + ¶meterCount, + ¶meterFootprint, + &returnCode); + + return returnCode; +} + class Frame { public: enum StackType { @@ -2017,6 +2044,28 @@ class Frame { } } + void referenceStackCall(bool isStatic, + ir::Value* methodValue, + object methodReference, + unsigned flags, + TraceElement* trace) + { + unsigned footprint + = methodReferenceParameterFootprint(t, methodReference, isStatic); + unsigned returnCode = methodReferenceReturnCode(t, methodReference); + ir::Value* result = c->stackCall(methodValue, + flags, + trace, + operandTypeForFieldCode(t, returnCode), + footprint); + + pop(footprint); + + if (returnCode != VoidField) { + pushReturnValue(returnCode, result); + } + } + unsigned startSubroutine(unsigned ip, avian::codegen::Promise* returnAddress) { pushAddress(absoluteAddressOperand(returnAddress)); @@ -3311,54 +3360,17 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall) return tailCall; } -unsigned -methodReferenceParameterFootprint(Thread* t, object reference, bool isStatic) -{ - return parameterFootprint - (t, reinterpret_cast - (&byteArrayBody(t, referenceSpec(t, reference), 0)), isStatic); -} - -int -methodReferenceReturnCode(Thread* t, object reference) -{ - unsigned parameterCount; - unsigned parameterFootprint; - unsigned returnCode; - scanMethodSpec - (t, reinterpret_cast - (&byteArrayBody(t, referenceSpec(t, reference), 0)), true, - ¶meterCount, ¶meterFootprint, &returnCode); - - return returnCode; -} - -void compileReferenceInvoke(MyThread* t, - Frame* frame, +void compileReferenceInvoke(Frame* frame, ir::Value* method, object reference, bool isStatic, bool tailCall) { - unsigned parameterFootprint - = methodReferenceParameterFootprint(t, reference, isStatic); - - int returnCode = methodReferenceReturnCode(t, reference); - - unsigned rSize = resultSize(t, returnCode); - - ir::Value* result - = frame->c->stackCall(method, + frame->referenceStackCall(isStatic, + method, + reference, tailCall ? Compiler::TailJump : 0, - frame->trace(0, 0), - operandTypeForFieldCode(t, returnCode), - parameterFootprint); - - frame->pop(parameterFootprint); - - if (rSize) { - frame->pushReturnValue(returnCode, result); - } + frame->trace(0, 0)); } void @@ -3372,8 +3384,7 @@ compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk, object pair = makePair(t, frame->context->method, reference); - compileReferenceInvoke(t, - frame, + compileReferenceInvoke(frame, c->call(c->constant(getThunk(t, thunk), types.address), 0, frame->trace(0, 0), @@ -5196,7 +5207,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, object pair = makePair(t, context->method, reference); compileReferenceInvoke( - t, frame, c->call( c->constant(getThunk(t, findVirtualMethodFromReferenceThunk), From 97ce7d2b4ea8e3ebdf564b6e8e6e0c064db62d99 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 16:40:57 -0600 Subject: [PATCH 36/89] pass CallEvent arguments in Slice as well --- include/avian/codegen/compiler.h | 5 +- src/codegen/compiler.cpp | 9 ++- src/codegen/compiler/event.cpp | 85 +++++++++++++-------- src/codegen/compiler/event.h | 15 ++-- src/compile.cpp | 125 ++++++++++++++++++------------- 5 files changed, 147 insertions(+), 92 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 31d0535082..18b7b6164e 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -12,6 +12,7 @@ #define AVIAN_CODEGEN_COMPILER_H #include +#include #include "avian/zone.h" #include "assembler.h" #include "ir.h" @@ -91,8 +92,8 @@ class Compiler { unsigned flags, TraceHandler* traceHandler, ir::Type resultType, - unsigned argumentFootprint /*, - util::Slice arguments*/) = 0; + unsigned argumentFootprint, + util::Slice arguments) = 0; virtual void return_(ir::Type type, ir::Value* value) = 0; virtual void return_() = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index f631c72f6d..e81b626b6b 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2497,7 +2497,8 @@ class MyCompiler: public Compiler { resultType.size(), argumentStack, index, - 0); + 0, + util::Slice(0, 0)); return result; } @@ -2506,7 +2507,8 @@ class MyCompiler: public Compiler { unsigned flags, TraceHandler* traceHandler, ir::Type resultType, - unsigned argumentFootprint) + unsigned argumentFootprint, + Slice arguments) { Value* result = value(&c, resultType); appendCall(&c, @@ -2517,7 +2519,8 @@ class MyCompiler: public Compiler { resultType.size(), c.stack, 0, - argumentFootprint); + argumentFootprint, + arguments); return result; } diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index ab6e8d2563..2b8bbc9a38 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -187,21 +187,27 @@ Link* link(Context* c, Event* predecessor, Link* nextPredecessor, Event* success class CallEvent: public Event { public: - CallEvent(Context* c, Value* address, unsigned flags, - TraceHandler* traceHandler, Value* result, unsigned resultSize, - Stack* argumentStack, unsigned argumentCount, - unsigned stackArgumentFootprint): - Event(c), - address(address), - traceHandler(traceHandler), - result(result), - returnAddressSurrogate(0), - framePointerSurrogate(0), - popIndex(0), - stackArgumentIndex(0), - flags(flags), - resultSize(resultSize), - stackArgumentFootprint(stackArgumentFootprint) + CallEvent(Context* c, + Value* address, + unsigned flags, + TraceHandler* traceHandler, + Value* result, + unsigned resultSize, + Stack* argumentStack, + unsigned argumentCount, + unsigned stackArgumentFootprint, + util::Slice arguments UNUSED) + : Event(c), + address(address), + traceHandler(traceHandler), + result(result), + returnAddressSurrogate(0), + framePointerSurrogate(0), + popIndex(0), + stackArgumentIndex(0), + flags(flags), + resultSize(resultSize), + stackArgumentFootprint(stackArgumentFootprint) { uint32_t registerMask = c->regFile->generalRegisters.mask; @@ -280,10 +286,12 @@ class CallEvent: public Event { Stack* stack = stackBefore; if (stackArgumentFootprint) { - RUNTIME_ARRAY(Value*, arguments, stackArgumentFootprint); + RUNTIME_ARRAY(Value*, argsArr, stackArgumentFootprint); for (int i = stackArgumentFootprint - 1; i >= 0; --i) { Value* v = stack->value; + ir::Value* v2 UNUSED = arguments[i]; stack = stack->next; + assert(c, v == v2); if ((vm::TargetBytesPerWord == 8 and (v == 0 or (i >= 1 and stack->value == 0))) @@ -291,10 +299,10 @@ class CallEvent: public Event { { assert(c, vm::TargetBytesPerWord == 8 or v->nextWord == stack->value); - RUNTIME_ARRAY_BODY(arguments)[i--] = stack->value; + RUNTIME_ARRAY_BODY(argsArr)[i--] = stack->value; stack = stack->next; } - RUNTIME_ARRAY_BODY(arguments)[i] = v; + RUNTIME_ARRAY_BODY(argsArr)[i] = v; } int returnAddressIndex; @@ -321,7 +329,7 @@ class CallEvent: public Event { } for (unsigned i = 0; i < stackArgumentFootprint; ++i) { - Value* v = RUNTIME_ARRAY_BODY(arguments)[i]; + Value* v = RUNTIME_ARRAY_BODY(argsArr)[i]; if (v) { int frameIndex = i + frameOffset; @@ -493,16 +501,28 @@ class CallEvent: public Event { unsigned stackArgumentFootprint; }; -void -appendCall(Context* c, Value* address, unsigned flags, - TraceHandler* traceHandler, Value* result, unsigned resultSize, - Stack* argumentStack, unsigned argumentCount, - unsigned stackArgumentFootprint) +void appendCall(Context* c, + Value* address, + unsigned flags, + TraceHandler* traceHandler, + Value* result, + unsigned resultSize, + Stack* argumentStack, + unsigned argumentCount, + unsigned stackArgumentFootprint, + util::Slice arguments) { - append(c, new(c->zone) - CallEvent(c, address, flags, traceHandler, result, - resultSize, argumentStack, argumentCount, - stackArgumentFootprint)); + append(c, + new (c->zone) CallEvent(c, + address, + flags, + traceHandler, + result, + resultSize, + argumentStack, + argumentCount, + stackArgumentFootprint, + arguments)); } @@ -944,7 +964,8 @@ appendCombine(Context* c, lir::TernaryOperation type, resultSize, argumentStack, stackSize, - 0); + 0, + util::Slice(0, 0)); } else { append (c, new(c->zone) @@ -1067,7 +1088,8 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, resultSize, argumentStack, ceilingDivide(firstSize, vm::TargetBytesPerWord), - 0); + 0, + util::Slice(0, 0)); } else { append(c, new(c->zone) TranslateEvent @@ -1432,7 +1454,8 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first 4, argumentStack, ceilingDivide(size, vm::TargetBytesPerWord) * 2, - 0); + 0, + util::Slice(0, 0)); appendBranch(c, thunkBranch(c, type), diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index 02eba8135f..b14c54a593 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -113,11 +113,16 @@ Link* link(Context* c, Event* predecessor, Link* nextPredecessor, Event* successor, Link* nextSuccessor, ForkState* forkState); -void -appendCall(Context* c, Value* address, unsigned flags, - TraceHandler* traceHandler, Value* result, unsigned resultSize, - Stack* argumentStack, unsigned argumentCount, - unsigned stackArgumentFootprint); +void appendCall(Context* c, + Value* address, + unsigned flags, + TraceHandler* traceHandler, + Value* result, + unsigned resultSize, + Stack* argumentStack, + unsigned argumentCount, + unsigned stackArgumentFootprint, + util::Slice arguments); void appendReturn(Context* c, unsigned size, Value* value); diff --git a/src/compile.cpp b/src/compile.cpp index e1a9ac3436..0d2706d550 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1221,56 +1221,60 @@ class Context { MyThread* t; }; - Context(MyThread* t, BootContext* bootContext, object method): - thread(t), - zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), - assembler(t->arch->makeAssembler(t->m->heap, &zone)), - client(t), - compiler(makeCompiler(t->m->system, assembler, &zone, &client)), - method(method), - bootContext(bootContext), - objectPool(0), - subroutines(0), - traceLog(0), - visitTable(makeVisitTable(t, &zone, method)), - rootTable(makeRootTable(t, &zone, method)), - subroutineTable(0), - executableAllocator(0), - executableStart(0), - executableSize(0), - objectPoolCount(0), - traceLogCount(0), - dirtyRoots(false), - leaf(true), - eventLog(t->m->system, t->m->heap, 1024), - protector(this), - resource(this) + Context(MyThread* t, BootContext* bootContext, object method) + : thread(t), + zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), + assembler(t->arch->makeAssembler(t->m->heap, &zone)), + client(t), + compiler(makeCompiler(t->m->system, assembler, &zone, &client)), + method(method), + bootContext(bootContext), + objectPool(0), + subroutines(0), + traceLog(0), + visitTable(makeVisitTable(t, &zone, method)), + rootTable(makeRootTable(t, &zone, method)), + subroutineTable(0), + executableAllocator(0), + executableStart(0), + executableSize(0), + objectPoolCount(0), + traceLogCount(0), + dirtyRoots(false), + leaf(true), + eventLog(t->m->system, t->m->heap, 1024), + protector(this), + resource(this), + argumentBuffer( + (ir::Value**)t->m->heap->allocate(256 * sizeof(ir::Value*)), + 256) // below the maximal allowed parameter count for Java { } - Context(MyThread* t): - thread(t), - zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), - assembler(t->arch->makeAssembler(t->m->heap, &zone)), - client(t), - compiler(0), - method(0), - bootContext(0), - objectPool(0), - subroutines(0), - traceLog(0), - visitTable(0), - rootTable(0), - subroutineTable(0), - executableAllocator(0), - executableStart(0), - executableSize(0), - objectPoolCount(0), - traceLogCount(0), - dirtyRoots(false), - leaf(true), - eventLog(t->m->system, t->m->heap, 0), - protector(this), - resource(this) + Context(MyThread* t) + : thread(t), + zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), + assembler(t->arch->makeAssembler(t->m->heap, &zone)), + client(t), + compiler(0), + method(0), + bootContext(0), + objectPool(0), + subroutines(0), + traceLog(0), + visitTable(0), + rootTable(0), + subroutineTable(0), + executableAllocator(0), + executableStart(0), + executableSize(0), + objectPoolCount(0), + traceLogCount(0), + dirtyRoots(false), + leaf(true), + eventLog(t->m->system, t->m->heap, 0), + protector(this), + resource(this), + argumentBuffer(0, 0) { } ~Context() { @@ -1291,6 +1295,10 @@ class Context { eventLog.dispose(); zone.dispose(); + + if (argumentBuffer.begin()) { + thread->m->heap->free(argumentBuffer.begin(), 256 * sizeof(ir::Value*)); + } } MyThread* thread; @@ -1316,6 +1324,7 @@ class Context { Vector eventLog; MyProtector protector; MyResource resource; + Slice argumentBuffer; }; unsigned @@ -2024,6 +2033,17 @@ class Frame { } } + Slice peekMethodArguments(unsigned footprint UNUSED) + { + ir::Value** ptr = context->argumentBuffer.items; + + for (unsigned i = 0; i < footprint; i++) { + *(ptr++) = c->peek(1, footprint - i - 1); + } + + return Slice(context->argumentBuffer.items, footprint); + } + void stackCall(ir::Value* methodValue, object methodObject, unsigned flags, @@ -2035,7 +2055,8 @@ class Frame { flags, trace, operandTypeForFieldCode(t, returnCode), - footprint); + footprint, + peekMethodArguments(footprint)); pop(footprint); @@ -2057,7 +2078,8 @@ class Frame { flags, trace, operandTypeForFieldCode(t, returnCode), - footprint); + footprint, + peekMethodArguments(footprint)); pop(footprint); @@ -5087,7 +5109,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0), operandTypeForFieldCode(t, returnCode), - parameterFootprint); + parameterFootprint, + frame->peekMethodArguments(parameterFootprint)); frame->pop(parameterFootprint); From 3c9a453d17b19a5a0f0aa3a7f415839f7b377d52 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 16:56:42 -0600 Subject: [PATCH 37/89] add extra asserts in CallEvent --- src/codegen/compiler/event.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 2b8bbc9a38..2ce2218dfa 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -288,21 +288,28 @@ class CallEvent: public Event { if (stackArgumentFootprint) { RUNTIME_ARRAY(Value*, argsArr, stackArgumentFootprint); for (int i = stackArgumentFootprint - 1; i >= 0; --i) { - Value* v = stack->value; - ir::Value* v2 UNUSED = arguments[i]; + Value* v = static_cast(arguments[i]); stack = stack->next; - assert(c, v == v2); - if ((vm::TargetBytesPerWord == 8 - and (v == 0 or (i >= 1 and stack->value == 0))) - or (vm::TargetBytesPerWord == 4 and v->nextWord != v)) - { - assert(c, vm::TargetBytesPerWord == 8 or v->nextWord == stack->value); + if ((vm::TargetBytesPerWord + == 8 and(v == 0 or(i >= 1 and arguments[i - 1] == 0))) + or(vm::TargetBytesPerWord == 4 and v->nextWord != v)) { + assert( + c, + vm::TargetBytesPerWord == 8 or v->nextWord == arguments[i - 1]); - RUNTIME_ARRAY_BODY(argsArr)[i--] = stack->value; + Value* v2 = static_cast(arguments[i - 1]); + RUNTIME_ARRAY_BODY(argsArr)[i] = v2; + arguments[i] = arguments[i - 1]; + --i; stack = stack->next; } RUNTIME_ARRAY_BODY(argsArr)[i] = v; + arguments[i] = v; + } + + for (size_t i = 0; i < arguments.count; i++) { + assert(c, arguments[i] == RUNTIME_ARRAY_BODY(argsArr)[i]); } int returnAddressIndex; From 69edeaadee53606a05d145ca243d5984d8d72176 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 17:04:36 -0600 Subject: [PATCH 38/89] remove redundant Compiler::stackCall footprint argument --- include/avian/codegen/compiler.h | 1 - src/codegen/compiler.cpp | 3 --- src/codegen/compiler/event.cpp | 28 +++++++--------------------- src/codegen/compiler/event.h | 1 - src/compile.cpp | 3 --- 5 files changed, 7 insertions(+), 29 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 18b7b6164e..5cd20d109d 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -92,7 +92,6 @@ class Compiler { unsigned flags, TraceHandler* traceHandler, ir::Type resultType, - unsigned argumentFootprint, util::Slice arguments) = 0; virtual void return_(ir::Type type, ir::Value* value) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index e81b626b6b..fa98b33d70 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2497,7 +2497,6 @@ class MyCompiler: public Compiler { resultType.size(), argumentStack, index, - 0, util::Slice(0, 0)); return result; @@ -2507,7 +2506,6 @@ class MyCompiler: public Compiler { unsigned flags, TraceHandler* traceHandler, ir::Type resultType, - unsigned argumentFootprint, Slice arguments) { Value* result = value(&c, resultType); @@ -2519,7 +2517,6 @@ class MyCompiler: public Compiler { resultType.size(), c.stack, 0, - argumentFootprint, arguments); return result; } diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 2ce2218dfa..e991876652 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -195,8 +195,7 @@ class CallEvent: public Event { unsigned resultSize, Stack* argumentStack, unsigned argumentCount, - unsigned stackArgumentFootprint, - util::Slice arguments UNUSED) + util::Slice arguments) : Event(c), address(address), traceHandler(traceHandler), @@ -207,13 +206,13 @@ class CallEvent: public Event { stackArgumentIndex(0), flags(flags), resultSize(resultSize), - stackArgumentFootprint(stackArgumentFootprint) + stackArgumentFootprint(arguments.count) { uint32_t registerMask = c->regFile->generalRegisters.mask; if (argumentCount) { assert(c, (flags & Compiler::TailJump) == 0); - assert(c, stackArgumentFootprint == 0); + assert(c, arguments.count == 0); Stack* s = argumentStack; unsigned index = 0; @@ -286,32 +285,24 @@ class CallEvent: public Event { Stack* stack = stackBefore; if (stackArgumentFootprint) { - RUNTIME_ARRAY(Value*, argsArr, stackArgumentFootprint); for (int i = stackArgumentFootprint - 1; i >= 0; --i) { Value* v = static_cast(arguments[i]); stack = stack->next; - if ((vm::TargetBytesPerWord - == 8 and(v == 0 or(i >= 1 and arguments[i - 1] == 0))) - or(vm::TargetBytesPerWord == 4 and v->nextWord != v)) { + if ((vm::TargetBytesPerWord == 8 + && (v == 0 || (i >= 1 && arguments[i - 1] == 0))) + || (vm::TargetBytesPerWord == 4 && v->nextWord != v)) { assert( c, vm::TargetBytesPerWord == 8 or v->nextWord == arguments[i - 1]); - Value* v2 = static_cast(arguments[i - 1]); - RUNTIME_ARRAY_BODY(argsArr)[i] = v2; arguments[i] = arguments[i - 1]; --i; stack = stack->next; } - RUNTIME_ARRAY_BODY(argsArr)[i] = v; arguments[i] = v; } - for (size_t i = 0; i < arguments.count; i++) { - assert(c, arguments[i] == RUNTIME_ARRAY_BODY(argsArr)[i]); - } - int returnAddressIndex; int framePointerIndex; int frameOffset; @@ -336,7 +327,7 @@ class CallEvent: public Event { } for (unsigned i = 0; i < stackArgumentFootprint; ++i) { - Value* v = RUNTIME_ARRAY_BODY(argsArr)[i]; + Value* v = static_cast(arguments[i]); if (v) { int frameIndex = i + frameOffset; @@ -516,7 +507,6 @@ void appendCall(Context* c, unsigned resultSize, Stack* argumentStack, unsigned argumentCount, - unsigned stackArgumentFootprint, util::Slice arguments) { append(c, @@ -528,7 +518,6 @@ void appendCall(Context* c, resultSize, argumentStack, argumentCount, - stackArgumentFootprint, arguments)); } @@ -971,7 +960,6 @@ appendCombine(Context* c, lir::TernaryOperation type, resultSize, argumentStack, stackSize, - 0, util::Slice(0, 0)); } else { append @@ -1095,7 +1083,6 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, resultSize, argumentStack, ceilingDivide(firstSize, vm::TargetBytesPerWord), - 0, util::Slice(0, 0)); } else { append(c, new(c->zone) @@ -1461,7 +1448,6 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first 4, argumentStack, ceilingDivide(size, vm::TargetBytesPerWord) * 2, - 0, util::Slice(0, 0)); appendBranch(c, diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index b14c54a593..41a02c5345 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -121,7 +121,6 @@ void appendCall(Context* c, unsigned resultSize, Stack* argumentStack, unsigned argumentCount, - unsigned stackArgumentFootprint, util::Slice arguments); void diff --git a/src/compile.cpp b/src/compile.cpp index 0d2706d550..36e19ecf8e 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -2055,7 +2055,6 @@ class Frame { flags, trace, operandTypeForFieldCode(t, returnCode), - footprint, peekMethodArguments(footprint)); pop(footprint); @@ -2078,7 +2077,6 @@ class Frame { flags, trace, operandTypeForFieldCode(t, returnCode), - footprint, peekMethodArguments(footprint)); pop(footprint); @@ -5109,7 +5107,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0), operandTypeForFieldCode(t, returnCode), - parameterFootprint, frame->peekMethodArguments(parameterFootprint)); frame->pop(parameterFootprint); From f9cbca8f7d5c62092d9d77ff18258dd03a390a4c Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 17:26:42 -0600 Subject: [PATCH 39/89] pair up stack for NativeCallingConvention --- include/avian/codegen/ir.h | 2 + src/codegen/compiler.cpp | 12 ++- src/codegen/compiler/event.cpp | 142 ++++++++++++++++++++++++++++++--- src/codegen/compiler/event.h | 3 + 4 files changed, 144 insertions(+), 15 deletions(-) diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h index 9c84e0c782..c66998c8c4 100644 --- a/include/avian/codegen/ir.h +++ b/include/avian/codegen/ir.h @@ -115,6 +115,8 @@ class Types { enum SignExtendMode { SignExtend, ZeroExtend }; +enum CallingConvention { NativeCallingConvention, AvianCallingConvention }; + class Value { public: ir::Type type; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index fa98b33d70..5d9537e582 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2460,7 +2460,7 @@ class MyCompiler: public Compiler { unsigned footprint = 0; unsigned size = TargetBytesPerWord; - RUNTIME_ARRAY(Value*, arguments, argumentCount); + RUNTIME_ARRAY(ir::Value*, arguments, argumentCount); int index = 0; for (unsigned i = 0; i < argumentCount; ++i) { Value* o = va_arg(a, Value*); @@ -2484,20 +2484,23 @@ class MyCompiler: public Compiler { Stack* argumentStack = c.stack; for (int i = index - 1; i >= 0; --i) { - argumentStack = compiler::stack - (&c, RUNTIME_ARRAY_BODY(arguments)[i], argumentStack); + argumentStack = compiler::stack( + &c, + static_cast(RUNTIME_ARRAY_BODY(arguments)[i]), + argumentStack); } Value* result = value(&c, resultType); appendCall(&c, static_cast(address), + ir::NativeCallingConvention, flags, traceHandler, result, resultType.size(), argumentStack, index, - util::Slice(0, 0)); + util::Slice(RUNTIME_ARRAY_BODY(arguments), index)); return result; } @@ -2511,6 +2514,7 @@ class MyCompiler: public Compiler { Value* result = value(&c, resultType); appendCall(&c, static_cast(address), + ir::AvianCallingConvention, flags, traceHandler, result, diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index e991876652..20759eb548 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -184,11 +184,110 @@ Link* link(Context* c, Event* predecessor, Link* nextPredecessor, Event* success (predecessor, nextPredecessor, successor, nextSuccessor, forkState); } +Value* maybeBuddySlice(Context* c, Value* v) +{ + if (v->home >= 0) { + Value* n = value(c, v->type); + appendBuddy(c, v, n); + return n; + } else { + return v; + } +} + +template +struct SliceStack : public Slice { + size_t capacity; + + SliceStack(T* items, size_t capacity) + : Slice(items + capacity, 0), capacity(capacity) + { + } + + void push(const T& item) + { + --Slice::items; + ++Slice::count; + *Slice::items = item; + } +}; + +template +struct FixedSliceStack : public SliceStack { + T itemArray[Capacity]; + + FixedSliceStack() : SliceStack(&itemArray[0], Capacity) + { + } +}; + +Value* pushWordSlice(Context* c, Value* v, SliceStack& slice) +{ + if (v) { + v = maybeBuddySlice(c, v); + } + + Stack* s = stack(c, v, c->stack); + assert(c, index > 0); + slice.push(v); + + // if (DebugFrame) { + // fprintf(stderr, "push %p\n", v); + // } + + if (v) { + v->home = frameIndex(c, s->index + c->localFootprint); + } + c->stack = s; + + return v; +} + +void pushSlice(Context* c, + unsigned footprint, + Value* v, + SliceStack& slice) +{ + assert(c, footprint); + + bool bigEndian = c->arch->bigEndian(); + + Value* low = v; + + if (bigEndian) { + v = pushWordSlice(c, v, slice); + } + + Value* high; + if (footprint > 1) { + assert(c, footprint == 2); + + if (vm::TargetBytesPerWord == 4) { + low->maybeSplit(c); + high = pushWordSlice(c, low->nextWord, slice); + } else { + high = pushWordSlice(c, 0, slice); + } + } else { + high = 0; + } + + if (not bigEndian) { + v = pushWordSlice(c, v, slice); + } + + if (high) { + v->nextWord = high; + high->nextWord = v; + high->wordIndex = 1; + } +} class CallEvent: public Event { public: CallEvent(Context* c, Value* address, + ir::CallingConvention callingConvention UNUSED, unsigned flags, TraceHandler* traceHandler, Value* result, @@ -206,13 +305,19 @@ class CallEvent: public Event { stackArgumentIndex(0), flags(flags), resultSize(resultSize), - stackArgumentFootprint(arguments.count) + stackArgumentFootprint(callingConvention == ir::AvianCallingConvention + ? arguments.count + : 0) { uint32_t registerMask = c->regFile->generalRegisters.mask; + assert(c, + callingConvention == ir::AvianCallingConvention + || argumentCount == arguments.count); + if (argumentCount) { assert(c, (flags & Compiler::TailJump) == 0); - assert(c, arguments.count == 0); + assert(c, stackArgumentFootprint == 0); Stack* s = argumentStack; unsigned index = 0; @@ -501,6 +606,7 @@ class CallEvent: public Event { void appendCall(Context* c, Value* address, + ir::CallingConvention callingConvention, unsigned flags, TraceHandler* traceHandler, Value* result, @@ -512,6 +618,7 @@ void appendCall(Context* c, append(c, new (c->zone) CallEvent(c, address, + callingConvention, flags, traceHandler, result, @@ -929,6 +1036,7 @@ appendCombine(Context* c, lir::TernaryOperation type, &thunk); if (thunk) { + FixedSliceStack slice; Stack* oldStack = c->stack; bool threadParameter; @@ -938,13 +1046,17 @@ appendCombine(Context* c, lir::TernaryOperation type, unsigned stackSize = ceilingDivide(secondSize, vm::TargetBytesPerWord) + ceilingDivide(firstSize, vm::TargetBytesPerWord); - compiler::push(c, ceilingDivide(secondSize, vm::TargetBytesPerWord), secondValue); - compiler::push(c, ceilingDivide(firstSize, vm::TargetBytesPerWord), firstValue); + pushSlice(c, + ceilingDivide(secondSize, vm::TargetBytesPerWord), + secondValue, + slice); + pushSlice( + c, ceilingDivide(firstSize, vm::TargetBytesPerWord), firstValue, slice); if (threadParameter) { ++ stackSize; - compiler::push(c, 1, threadRegister(c)); + pushSlice(c, 1, threadRegister(c), slice); } Stack* argumentStack = c->stack; @@ -954,13 +1066,14 @@ appendCombine(Context* c, lir::TernaryOperation type, value(c, ir::Type(ir::Type::Address, vm::TargetBytesPerWord), constantSite(c, handler)), + ir::NativeCallingConvention, 0, 0, resultValue, resultSize, argumentStack, stackSize, - util::Slice(0, 0)); + slice); } else { append (c, new(c->zone) @@ -1066,8 +1179,10 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, if (thunk) { Stack* oldStack = c->stack; + FixedSliceStack slice; - compiler::push(c, ceilingDivide(firstSize, vm::TargetBytesPerWord), firstValue); + pushSlice( + c, ceilingDivide(firstSize, vm::TargetBytesPerWord), firstValue, slice); Stack* argumentStack = c->stack; c->stack = oldStack; @@ -1077,13 +1192,14 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, ir::Type(ir::Type::Address, vm::TargetBytesPerWord), constantSite( c, c->client->getThunk(type, firstSize, resultSize))), + ir::NativeCallingConvention, 0, 0, resultValue, resultSize, argumentStack, ceilingDivide(firstSize, vm::TargetBytesPerWord), - util::Slice(0, 0)); + slice); } else { append(c, new(c->zone) TranslateEvent @@ -1422,6 +1538,7 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first vm::TargetBytesPerWord, &thunk); if (thunk) { + FixedSliceStack slice; Stack* oldStack = c->stack; bool threadParameter; @@ -1430,8 +1547,10 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first assert(c, not threadParameter); - compiler::push(c, ceilingDivide(size, vm::TargetBytesPerWord), secondValue); - compiler::push(c, ceilingDivide(size, vm::TargetBytesPerWord), firstValue); + pushSlice( + c, ceilingDivide(size, vm::TargetBytesPerWord), secondValue, slice); + pushSlice( + c, ceilingDivide(size, vm::TargetBytesPerWord), firstValue, slice); Stack* argumentStack = c->stack; c->stack = oldStack; @@ -1442,13 +1561,14 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first value(c, ir::Type(ir::Type::Address, vm::TargetBytesPerWord), constantSite(c, handler)), + ir::NativeCallingConvention, 0, 0, result, 4, argumentStack, ceilingDivide(size, vm::TargetBytesPerWord) * 2, - util::Slice(0, 0)); + slice); appendBranch(c, thunkBranch(c, type), diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index 41a02c5345..31d2483fda 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -115,6 +115,7 @@ link(Context* c, Event* predecessor, Link* nextPredecessor, Event* successor, void appendCall(Context* c, Value* address, + ir::CallingConvention callingConvention, unsigned flags, TraceHandler* traceHandler, Value* result, @@ -168,6 +169,8 @@ appendSaveLocals(Context* c); void appendDummy(Context* c); +void appendBuddy(Context* c, Value* original, Value* buddy); + } // namespace compiler } // namespace codegen } // namespace avian From 1318b9ca2a6cda3256bee5279a3676f20dd38997 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 19:07:45 -0600 Subject: [PATCH 40/89] remove redundant CallEvent::argumentCount parameter --- src/codegen/compiler.cpp | 2 -- src/codegen/compiler/event.cpp | 25 ++++++++----------------- src/codegen/compiler/event.h | 1 - 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 5d9537e582..c287b352a4 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2499,7 +2499,6 @@ class MyCompiler: public Compiler { result, resultType.size(), argumentStack, - index, util::Slice(RUNTIME_ARRAY_BODY(arguments), index)); return result; @@ -2520,7 +2519,6 @@ class MyCompiler: public Compiler { result, resultType.size(), c.stack, - 0, arguments); return result; } diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 20759eb548..fa714d115b 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -293,7 +293,6 @@ class CallEvent: public Event { Value* result, unsigned resultSize, Stack* argumentStack, - unsigned argumentCount, util::Slice arguments) : Event(c), address(address), @@ -311,11 +310,7 @@ class CallEvent: public Event { { uint32_t registerMask = c->regFile->generalRegisters.mask; - assert(c, - callingConvention == ir::AvianCallingConvention - || argumentCount == arguments.count); - - if (argumentCount) { + if (callingConvention == ir::NativeCallingConvention) { assert(c, (flags & Compiler::TailJump) == 0); assert(c, stackArgumentFootprint == 0); @@ -325,9 +320,10 @@ class CallEvent: public Event { while (true) { unsigned footprint - = (argumentIndex + 1 < argumentCount - and s->value->nextWord == s->next->value) - ? 2 : 1; + = (argumentIndex + 1 < arguments.count and s->value->nextWord + == s->next->value) + ? 2 + : 1; if (index % (c->arch->argumentAlignment() ? footprint : 1)) { ++ index; @@ -363,7 +359,7 @@ class CallEvent: public Event { ++ index; - if ((++ argumentIndex) < argumentCount) { + if ((++argumentIndex) < arguments.count) { s = s->next; } else { break; @@ -389,7 +385,7 @@ class CallEvent: public Event { Stack* stack = stackBefore; - if (stackArgumentFootprint) { + if (callingConvention == ir::AvianCallingConvention) { for (int i = stackArgumentFootprint - 1; i >= 0; --i) { Value* v = static_cast(arguments[i]); stack = stack->next; @@ -413,7 +409,7 @@ class CallEvent: public Event { int frameOffset; if (TailCalls and (flags & Compiler::TailJump)) { - assert(c, argumentCount == 0); + assert(c, arguments.count == 0); int base = frameBase(c); returnAddressIndex = base + c->arch->returnAddressOffset(); @@ -612,7 +608,6 @@ void appendCall(Context* c, Value* result, unsigned resultSize, Stack* argumentStack, - unsigned argumentCount, util::Slice arguments) { append(c, @@ -624,7 +619,6 @@ void appendCall(Context* c, result, resultSize, argumentStack, - argumentCount, arguments)); } @@ -1072,7 +1066,6 @@ appendCombine(Context* c, lir::TernaryOperation type, resultValue, resultSize, argumentStack, - stackSize, slice); } else { append @@ -1198,7 +1191,6 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, resultValue, resultSize, argumentStack, - ceilingDivide(firstSize, vm::TargetBytesPerWord), slice); } else { append(c, new(c->zone) @@ -1567,7 +1559,6 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first result, 4, argumentStack, - ceilingDivide(size, vm::TargetBytesPerWord) * 2, slice); appendBranch(c, diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index 31d2483fda..90031305f1 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -121,7 +121,6 @@ void appendCall(Context* c, Value* result, unsigned resultSize, Stack* argumentStack, - unsigned argumentCount, util::Slice arguments); void From d2e9911161d53f6005032e6cb6ca261c972ce697 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 19:49:43 -0600 Subject: [PATCH 41/89] add asserts in CallEvent --- src/codegen/compiler/event.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index fa714d115b..9e94787d03 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -319,6 +319,10 @@ class CallEvent: public Event { unsigned argumentIndex = 0; while (true) { + assert(c, arguments[index] == s->value); + assert(c, + argumentIndex + 1 >= arguments.count || arguments[index + 1] + == s->next->value); unsigned footprint = (argumentIndex + 1 < arguments.count and s->value->nextWord == s->next->value) From fe2962830c65b42110e1ce0e298a1cef1fda24a3 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 20:27:45 -0600 Subject: [PATCH 42/89] remove unused CallEvent::argumentStack variable, prepare to remove stack manipulation from NativeCallingConvention calls --- src/codegen/compiler.cpp | 10 ---- src/codegen/compiler/event.cpp | 90 ++++++++++++++++++++-------------- src/codegen/compiler/event.h | 1 - 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index c287b352a4..faeea8665b 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2482,14 +2482,6 @@ class MyCompiler: public Compiler { va_end(a); - Stack* argumentStack = c.stack; - for (int i = index - 1; i >= 0; --i) { - argumentStack = compiler::stack( - &c, - static_cast(RUNTIME_ARRAY_BODY(arguments)[i]), - argumentStack); - } - Value* result = value(&c, resultType); appendCall(&c, static_cast(address), @@ -2498,7 +2490,6 @@ class MyCompiler: public Compiler { traceHandler, result, resultType.size(), - argumentStack, util::Slice(RUNTIME_ARRAY_BODY(arguments), index)); return result; @@ -2518,7 +2509,6 @@ class MyCompiler: public Compiler { traceHandler, result, resultType.size(), - c.stack, arguments); return result; } diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 9e94787d03..7c87609341 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -221,20 +221,27 @@ struct FixedSliceStack : public SliceStack { } }; -Value* pushWordSlice(Context* c, Value* v, SliceStack& slice) +Value* pushWordSlice(Context* c, + Value* v, + size_t stackBase UNUSED, + SliceStack& slice) { if (v) { v = maybeBuddySlice(c, v); } + size_t index UNUSED = slice.count; + Stack* s = stack(c, v, c->stack); - assert(c, index > 0); + assert(c, slice.count < slice.capacity); slice.push(v); // if (DebugFrame) { // fprintf(stderr, "push %p\n", v); // } + assert(c, s->index == index + stackBase); + if (v) { v->home = frameIndex(c, s->index + c->localFootprint); } @@ -246,6 +253,7 @@ Value* pushWordSlice(Context* c, Value* v, SliceStack& slice) void pushSlice(Context* c, unsigned footprint, Value* v, + size_t stackBase, SliceStack& slice) { assert(c, footprint); @@ -255,7 +263,7 @@ void pushSlice(Context* c, Value* low = v; if (bigEndian) { - v = pushWordSlice(c, v, slice); + v = pushWordSlice(c, v, stackBase, slice); } Value* high; @@ -264,16 +272,16 @@ void pushSlice(Context* c, if (vm::TargetBytesPerWord == 4) { low->maybeSplit(c); - high = pushWordSlice(c, low->nextWord, slice); + high = pushWordSlice(c, low->nextWord, stackBase, slice); } else { - high = pushWordSlice(c, 0, slice); + high = pushWordSlice(c, 0, stackBase, slice); } } else { high = 0; } if (not bigEndian) { - v = pushWordSlice(c, v, slice); + v = pushWordSlice(c, v, stackBase, slice); } if (high) { @@ -292,7 +300,6 @@ class CallEvent: public Event { TraceHandler* traceHandler, Value* result, unsigned resultSize, - Stack* argumentStack, util::Slice arguments) : Event(c), address(address), @@ -314,18 +321,15 @@ class CallEvent: public Event { assert(c, (flags & Compiler::TailJump) == 0); assert(c, stackArgumentFootprint == 0); - Stack* s = argumentStack; unsigned index = 0; unsigned argumentIndex = 0; while (true) { - assert(c, arguments[index] == s->value); - assert(c, - argumentIndex + 1 >= arguments.count || arguments[index + 1] - == s->next->value); + Value* v = static_cast(arguments[index]); + unsigned footprint - = (argumentIndex + 1 < arguments.count and s->value->nextWord - == s->next->value) + = (argumentIndex + 1 < arguments.count and v->nextWord + == arguments[index + 1]) ? 2 : 1; @@ -338,9 +342,9 @@ class CallEvent: public Event { <= c->arch->argumentRegisterCount()) { int number = c->arch->argumentRegister(index); - + if (DebugReads) { - fprintf(stderr, "reg %d arg read %p\n", number, s->value); + fprintf(stderr, "reg %d arg read %p\n", number, v); } targetMask = SiteMask::fixedRegisterMask(number); @@ -353,19 +357,17 @@ class CallEvent: public Event { unsigned frameIndex = index - c->arch->argumentRegisterCount(); if (DebugReads) { - fprintf(stderr, "stack %d arg read %p\n", frameIndex, s->value); + fprintf(stderr, "stack %d arg read %p\n", frameIndex, v); } targetMask = SiteMask(1 << lir::MemoryOperand, 0, frameIndex); } - this->addRead(c, s->value, targetMask); + this->addRead(c, v, targetMask); ++ index; - if ((++argumentIndex) < arguments.count) { - s = s->next; - } else { + if ((++argumentIndex) >= arguments.count) { break; } } @@ -390,6 +392,7 @@ class CallEvent: public Event { Stack* stack = stackBefore; if (callingConvention == ir::AvianCallingConvention) { + // assert(c, argumentStack = ) for (int i = stackArgumentFootprint - 1; i >= 0; --i) { Value* v = static_cast(arguments[i]); stack = stack->next; @@ -611,7 +614,6 @@ void appendCall(Context* c, TraceHandler* traceHandler, Value* result, unsigned resultSize, - Stack* argumentStack, util::Slice arguments) { append(c, @@ -622,7 +624,6 @@ void appendCall(Context* c, traceHandler, result, resultSize, - argumentStack, arguments)); } @@ -1036,6 +1037,7 @@ appendCombine(Context* c, lir::TernaryOperation type, if (thunk) { FixedSliceStack slice; Stack* oldStack = c->stack; + size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; intptr_t handler = c->client->getThunk @@ -1047,17 +1049,21 @@ appendCombine(Context* c, lir::TernaryOperation type, pushSlice(c, ceilingDivide(secondSize, vm::TargetBytesPerWord), secondValue, + stackBase, + slice); + pushSlice(c, + ceilingDivide(firstSize, vm::TargetBytesPerWord), + firstValue, + stackBase, slice); - pushSlice( - c, ceilingDivide(firstSize, vm::TargetBytesPerWord), firstValue, slice); if (threadParameter) { ++ stackSize; - pushSlice(c, 1, threadRegister(c), slice); + pushSlice(c, 1, threadRegister(c), stackBase, slice); } - Stack* argumentStack = c->stack; + // assert(c, c->stack == oldStack); c->stack = oldStack; appendCall(c, @@ -1069,7 +1075,6 @@ appendCombine(Context* c, lir::TernaryOperation type, 0, resultValue, resultSize, - argumentStack, slice); } else { append @@ -1176,12 +1181,16 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, if (thunk) { Stack* oldStack = c->stack; + size_t stackBase = c->stack ? c->stack->index + 1 : 0; FixedSliceStack slice; - pushSlice( - c, ceilingDivide(firstSize, vm::TargetBytesPerWord), firstValue, slice); + pushSlice(c, + ceilingDivide(firstSize, vm::TargetBytesPerWord), + firstValue, + stackBase, + slice); - Stack* argumentStack = c->stack; + // assert(c, c->stack == oldStack); c->stack = oldStack; appendCall(c, @@ -1194,7 +1203,6 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, 0, resultValue, resultSize, - argumentStack, slice); } else { append(c, new(c->zone) @@ -1536,6 +1544,7 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first if (thunk) { FixedSliceStack slice; Stack* oldStack = c->stack; + size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; intptr_t handler = c->client->getThunk @@ -1543,12 +1552,18 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first assert(c, not threadParameter); - pushSlice( - c, ceilingDivide(size, vm::TargetBytesPerWord), secondValue, slice); - pushSlice( - c, ceilingDivide(size, vm::TargetBytesPerWord), firstValue, slice); + pushSlice(c, + ceilingDivide(size, vm::TargetBytesPerWord), + secondValue, + stackBase, + slice); + pushSlice(c, + ceilingDivide(size, vm::TargetBytesPerWord), + firstValue, + stackBase, + slice); - Stack* argumentStack = c->stack; + // assert(c, c->stack == oldStack); c->stack = oldStack; Value* result @@ -1562,7 +1577,6 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first 0, result, 4, - argumentStack, slice); appendBranch(c, diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index 90031305f1..8ed0bc3496 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -120,7 +120,6 @@ void appendCall(Context* c, TraceHandler* traceHandler, Value* result, unsigned resultSize, - Stack* argumentStack, util::Slice arguments); void From cfc3bd212b98e0efc1076ef2b774ab2eb511edbf Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 20:30:28 -0600 Subject: [PATCH 43/89] remove stack manipulation from NativeCallingConvention calls --- src/codegen/compiler/event.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 7c87609341..f16ce1c81e 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -76,8 +76,6 @@ Site* pickSiteOrMove(Context* c, Value* src, Value* dst, Site* nextWord, unsigned index); -void push(Context* c, unsigned footprint, Value* v); - Site* pickTargetSite(Context* c, Read* read, bool intersectRead = false, unsigned registerReserveCount = 0, @@ -232,7 +230,6 @@ Value* pushWordSlice(Context* c, size_t index UNUSED = slice.count; - Stack* s = stack(c, v, c->stack); assert(c, slice.count < slice.capacity); slice.push(v); @@ -240,12 +237,9 @@ Value* pushWordSlice(Context* c, // fprintf(stderr, "push %p\n", v); // } - assert(c, s->index == index + stackBase); - if (v) { - v->home = frameIndex(c, s->index + c->localFootprint); + v->home = frameIndex(c, index + stackBase + c->localFootprint); } - c->stack = s; return v; } @@ -295,7 +289,7 @@ class CallEvent: public Event { public: CallEvent(Context* c, Value* address, - ir::CallingConvention callingConvention UNUSED, + ir::CallingConvention callingConvention, unsigned flags, TraceHandler* traceHandler, Value* result, @@ -392,7 +386,6 @@ class CallEvent: public Event { Stack* stack = stackBefore; if (callingConvention == ir::AvianCallingConvention) { - // assert(c, argumentStack = ) for (int i = stackArgumentFootprint - 1; i >= 0; --i) { Value* v = static_cast(arguments[i]); stack = stack->next; @@ -1036,7 +1029,7 @@ appendCombine(Context* c, lir::TernaryOperation type, if (thunk) { FixedSliceStack slice; - Stack* oldStack = c->stack; + Stack* oldStack UNUSED = c->stack; size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; @@ -1063,8 +1056,7 @@ appendCombine(Context* c, lir::TernaryOperation type, pushSlice(c, 1, threadRegister(c), stackBase, slice); } - // assert(c, c->stack == oldStack); - c->stack = oldStack; + assert(c, c->stack == oldStack); appendCall(c, value(c, @@ -1180,7 +1172,7 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, resultSize, &thunk); if (thunk) { - Stack* oldStack = c->stack; + Stack* oldStack UNUSED = c->stack; size_t stackBase = c->stack ? c->stack->index + 1 : 0; FixedSliceStack slice; @@ -1190,8 +1182,7 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, stackBase, slice); - // assert(c, c->stack == oldStack); - c->stack = oldStack; + assert(c, c->stack == oldStack); appendCall(c, value(c, @@ -1543,7 +1534,7 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first if (thunk) { FixedSliceStack slice; - Stack* oldStack = c->stack; + Stack* oldStack UNUSED = c->stack; size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; @@ -1563,8 +1554,7 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first stackBase, slice); - // assert(c, c->stack == oldStack); - c->stack = oldStack; + assert(c, c->stack == oldStack); Value* result = value(c, ir::Type(ir::Type::Address, vm::TargetBytesPerWord)); From ae534bed5f38efb68bee2e415de3cc23c58542fa Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 20:31:27 -0600 Subject: [PATCH 44/89] cleanup --- src/codegen/compiler/event.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index f16ce1c81e..c03c0a3a5e 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -1029,7 +1029,6 @@ appendCombine(Context* c, lir::TernaryOperation type, if (thunk) { FixedSliceStack slice; - Stack* oldStack UNUSED = c->stack; size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; @@ -1056,8 +1055,6 @@ appendCombine(Context* c, lir::TernaryOperation type, pushSlice(c, 1, threadRegister(c), stackBase, slice); } - assert(c, c->stack == oldStack); - appendCall(c, value(c, ir::Type(ir::Type::Address, vm::TargetBytesPerWord), @@ -1172,7 +1169,6 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, resultSize, &thunk); if (thunk) { - Stack* oldStack UNUSED = c->stack; size_t stackBase = c->stack ? c->stack->index + 1 : 0; FixedSliceStack slice; @@ -1182,8 +1178,6 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, stackBase, slice); - assert(c, c->stack == oldStack); - appendCall(c, value(c, ir::Type(ir::Type::Address, vm::TargetBytesPerWord), @@ -1534,7 +1528,6 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first if (thunk) { FixedSliceStack slice; - Stack* oldStack UNUSED = c->stack; size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; @@ -1554,8 +1547,6 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first stackBase, slice); - assert(c, c->stack == oldStack); - Value* result = value(c, ir::Type(ir::Type::Address, vm::TargetBytesPerWord)); appendCall(c, From 9f36a8e0ec6664bb9575c37e54eb8abf2ab3adda Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 20:42:16 -0600 Subject: [PATCH 45/89] prepare to move stack manipulation out of CallEvent --- src/codegen/compiler/event.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index c03c0a3a5e..f7fbaf77b8 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -386,6 +386,10 @@ class CallEvent: public Event { Stack* stack = stackBefore; if (callingConvention == ir::AvianCallingConvention) { + Stack* s2 = stack; + for (size_t i = 0; i < arguments.count; i++) { + s2 = s2->next; + } for (int i = stackArgumentFootprint - 1; i >= 0; --i) { Value* v = static_cast(arguments[i]); stack = stack->next; @@ -404,6 +408,8 @@ class CallEvent: public Event { arguments[i] = v; } + assert(c, s2 == stack); + int returnAddressIndex; int framePointerIndex; int frameOffset; @@ -492,6 +498,8 @@ class CallEvent: public Event { virtual void compile(Context* c) { lir::UnaryOperation op; + unsigned footprint = c->arch->argumentFootprint(stackArgumentFootprint); + if (TailCalls and (flags & Compiler::TailJump)) { if (flags & Compiler::LongJumpOrCall) { if (flags & Compiler::Aligned) { @@ -530,9 +538,9 @@ class CallEvent: public Event { fps = lir::NoRegister; } - int offset - = static_cast(c->arch->argumentFootprint(stackArgumentFootprint)) - - static_cast(c->arch->argumentFootprint(c->parameterFootprint)); + int offset = static_cast(footprint) + - static_cast( + c->arch->argumentFootprint(c->parameterFootprint)); c->assembler->popFrameForTailCall(c->alignedFrameSize, offset, ras, fps); } else if (flags & Compiler::LongJumpOrCall) { @@ -563,14 +571,8 @@ class CallEvent: public Event { if (framePointerSurrogate) { framePointerSurrogate->source->thaw(c, framePointerSurrogate); } - } else { - unsigned footprint = c->arch->argumentFootprint - (stackArgumentFootprint); - - if (footprint > c->arch->stackAlignmentInWords()) { - c->assembler->adjustFrame - (footprint - c->arch->stackAlignmentInWords()); - } + } else if (footprint > c->arch->stackAlignmentInWords()) { + c->assembler->adjustFrame(footprint - c->arch->stackAlignmentInWords()); } } From d62d08373330d2edbbebcdb72b939efa38498344 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 20:56:47 -0600 Subject: [PATCH 46/89] remove stack manipulation from AvianCallingConvention loop --- src/codegen/compiler.cpp | 2 ++ src/codegen/compiler/event.cpp | 7 +------ src/compile.cpp | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index faeea8665b..319809d774 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2502,6 +2502,7 @@ class MyCompiler: public Compiler { Slice arguments) { Value* result = value(&c, resultType); + Stack* b UNUSED = c.stack; appendCall(&c, static_cast(address), ir::AvianCallingConvention, @@ -2510,6 +2511,7 @@ class MyCompiler: public Compiler { result, resultType.size(), arguments); + assert(&c, c.stack == b); return result; } diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index f7fbaf77b8..0308a07cc9 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -386,13 +386,11 @@ class CallEvent: public Event { Stack* stack = stackBefore; if (callingConvention == ir::AvianCallingConvention) { - Stack* s2 = stack; for (size_t i = 0; i < arguments.count; i++) { - s2 = s2->next; + stack = stack->next; } for (int i = stackArgumentFootprint - 1; i >= 0; --i) { Value* v = static_cast(arguments[i]); - stack = stack->next; if ((vm::TargetBytesPerWord == 8 && (v == 0 || (i >= 1 && arguments[i - 1] == 0))) @@ -403,13 +401,10 @@ class CallEvent: public Event { arguments[i] = arguments[i - 1]; --i; - stack = stack->next; } arguments[i] = v; } - assert(c, s2 == stack); - int returnAddressIndex; int framePointerIndex; int frameOffset; diff --git a/src/compile.cpp b/src/compile.cpp index 36e19ecf8e..0a8684afeb 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -2033,7 +2033,7 @@ class Frame { } } - Slice peekMethodArguments(unsigned footprint UNUSED) + Slice peekMethodArguments(unsigned footprint) { ir::Value** ptr = context->argumentBuffer.items; From 43eb49cf539d94ec002922ad544e43c1e0254aaa Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 22:50:29 -0600 Subject: [PATCH 47/89] fix sizing of some stack ints --- include/avian/codegen/compiler.h | 3 +++ src/codegen/compiler.cpp | 19 ++++++++++++++++--- src/compile.cpp | 18 +++++++++--------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 5cd20d109d..109d8891f8 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -114,6 +114,9 @@ class Compiler { ir::Type truncateType, ir::Value* src) = 0; + virtual ir::Value* truncate(ir::Type type, ir::Type srcType, ir::Value* src) + = 0; + virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) = 0; virtual ir::Value* load(ir::SignExtendMode signExtend, ir::Type srcType, diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 319809d774..6e6452b60d 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2515,12 +2515,12 @@ class MyCompiler: public Compiler { return result; } - virtual void return_(ir::Type type, ir::Value* value) + virtual void return_(ir::Type type, ir::Value* a) { // TODO: once type information is flowed properly, enable this assert. // Some time later, we can remove the parameter. - // assert(&c, static_cast(value)->type == type); - appendReturn(&c, type.size(), static_cast(value)); + // assert(&c, a->type == type); + appendReturn(&c, type.size(), static_cast(a)); } virtual void return_() @@ -2614,6 +2614,19 @@ class MyCompiler: public Compiler { static_cast(index), handler); } + virtual ir::Value* truncate(ir::Type type, ir::Type srcType, ir::Value* src) + { + Value* dst = value(&c, type); + appendMove(&c, + lir::Move, + srcType.size(), + srcType.size(), + static_cast(src), + type.size(), + dst); + return dst; + } + virtual ir::Value* truncateThenExtend(ir::SignExtendMode signExtend, ir::Type extendType, ir::Type truncateType, diff --git a/src/compile.cpp b/src/compile.cpp index 0a8684afeb..b506b9f990 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1760,6 +1760,7 @@ class Frame { void pushLongQuiet(ir::Value* o) { + // assert(t, o->type == types.i8); pushQuiet(types.i8, o); } @@ -4357,7 +4358,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case areturn: { handleExit(t, frame); - c->return_(types.address, frame->popObject()); + c->return_(types.object, frame->popObject()); } goto next; case arraylength: { @@ -5329,8 +5330,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case l2i: - frame->pushInt( - c->load(ir::SignExtend, types.i8, frame->popLong(), types.address)); + frame->pushInt(c->truncate(types.i4, types.i8, frame->popLong())); break; case ladd: @@ -5366,11 +5366,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lconst_0: - frame->pushLong(c->constant(0, types.i4)); + frame->pushLong(c->constant(0, types.i8)); break; case lconst_1: - frame->pushLong(c->constant(1, types.i4)); + frame->pushLong(c->constant(1, types.i8)); break; case ldc: @@ -5388,7 +5388,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (singletonIsObject(t, pool, index - 1)) { object v = singletonObject(t, pool, index - 1); - loadMemoryBarrier(); + loadMemoryBarrier(); if (objectClass(t, v) == type(t, Machine::ReferenceType)) { object reference = v; @@ -5809,7 +5809,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ByteField: case BooleanField: c->store( - types.address, + types.i4, value, c->memory(table, types.i1, targetFieldOffset(context, field))); break; @@ -5817,7 +5817,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case CharField: case ShortField: c->store( - types.address, + types.i4, value, c->memory(table, types.i2, targetFieldOffset(context, field))); break; @@ -5831,7 +5831,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case IntField: c->store( - types.address, + types.i4, value, c->memory(table, types.i4, targetFieldOffset(context, field))); break; From cb7f570f20dfb7e4e913957c0f0ae677dadcb82e Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Fri, 2 May 2014 09:01:57 -0600 Subject: [PATCH 48/89] begin enforcing more strong typing --- include/avian/codegen/ir.h | 6 +- src/codegen/compiler.cpp | 7 +- src/compile.cpp | 159 ++++++++++++++++++++++++++----------- 3 files changed, 124 insertions(+), 48 deletions(-) diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h index c66998c8c4..a1e4d38001 100644 --- a/include/avian/codegen/ir.h +++ b/include/avian/codegen/ir.h @@ -33,7 +33,11 @@ class Type { // Represents the lack of a return value // TODO: remove when possible - Void + Void, + + // Represents some arbitrary type that should not be accessed + // TODO: remove when possible + Invalid }; private: diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 6e6452b60d..a9d021121e 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -1224,6 +1224,7 @@ unsigned typeFootprint(Context* c, ir::Type type) case ir::Type::Object: case ir::Type::Address: case ir::Type::Half: + case ir::Type::Invalid: return 1; case ir::Type::Void: return 0; @@ -1257,7 +1258,9 @@ Value* loadLocal(Context* c, ir::Type type, unsigned index) || c->locals[index].value->type.flavor() == ir::Type::Object // TODO: this is a very java-specific hole in the type system. Get // rid of it: - || c->locals[index].value->type.flavor() == ir::Type::Address); + || c->locals[index].value->type.flavor() == ir::Type::Address + // TODO Temporary hack for Subroutine test!!! + || c->locals[index].value->type.flavor() == ir::Type::Invalid); return c->locals[index].value; } @@ -2279,7 +2282,7 @@ class MyCompiler: public Compiler { for (unsigned li = 0; li < c.localFootprint; ++li) { Local* local = c.locals + li; if (local->value == 0) { - initLocal(1, li, ir::Type(ir::Type::Address, TargetBytesPerWord)); + initLocal(1, li, ir::Type(ir::Type::Invalid, TargetBytesPerWord)); } } } diff --git a/src/compile.cpp b/src/compile.cpp index b506b9f990..7667018d05 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1774,12 +1774,27 @@ class Frame { return popQuiet(types.i8); } - void pushInt(ir::Value* o) + void pushSmall(ir::Value* o) { pushQuiet(types.i4, o); pushedInt(); } + void pushInt(ir::Value* o) + { + assert(t, + o->type.flavor() == ir::Type::Integer + // TODO Temporary hack for Subroutine test!!! + || o->type.flavor() == ir::Type::Invalid); + pushSmall(o); + } + + void pushFloat(ir::Value* o) + { + assert(t, o->type.flavor() == ir::Type::Float); + pushSmall(o); + } + void pushAddress(ir::Value* o) { pushQuiet(types.i4, o); @@ -1788,7 +1803,11 @@ class Frame { void pushObject(ir::Value* o) { - assert(t, o->type == types.object || o->type.flavor() == ir::Type::Address); + assert(t, + o->type == types.object + || o->type.flavor() == ir::Type::Address + // TODO Temporary hack for Subroutine test!!! + || o->type.flavor() == ir::Type::Invalid); pushQuiet(types.object, o); pushedObject(); } @@ -1799,12 +1818,27 @@ class Frame { pushedObject(); } - void pushLong(ir::Value* o) + void pushLarge(ir::Value* o) { pushLongQuiet(o); pushedLong(); } + void pushLong(ir::Value* o) + { + assert(t, + o->type.flavor() == ir::Type::Integer + // TODO Temporary hack for Subroutine test!!! + || o->type.flavor() == ir::Type::Invalid); + pushLarge(o); + } + + void pushDouble(ir::Value* o) + { + assert(t, o->type.flavor() == ir::Type::Float); + pushLarge(o); + } + void pop(unsigned count) { popped(count); c->popped(count); @@ -1833,11 +1867,23 @@ class Frame { pushInt(loadLocal(context, 1, types.i4, index)); } + void loadFloat(unsigned index) + { + assert(t, index < localSize()); + pushFloat(loadLocal(context, 1, types.f4, index)); + } + void loadLong(unsigned index) { assert(t, index < static_cast(localSize() - 1)); pushLong(loadLocal(context, 2, types.i8, index)); } + void loadDouble(unsigned index) + { + assert(t, index < static_cast(localSize() - 1)); + pushDouble(loadLocal(context, 2, types.f8, index)); + } + void loadObject(unsigned index) { assert(t, index < localSize()); pushObject(loadLocal(context, 1, types.object, index)); @@ -2018,16 +2064,18 @@ class Frame { case BooleanField: case CharField: case ShortField: - case FloatField: case IntField: return pushInt(result); + case FloatField: + return pushFloat(result); case ObjectField: return pushObject(result); case LongField: - case DoubleField: return pushLong(result); + case DoubleField: + return pushDouble(result); default: abort(t); @@ -3776,7 +3824,7 @@ intrinsic(MyThread* t, Frame* frame, object target) if (MATCH(methodName(t, target), "sqrt") and MATCH(methodSpec(t, target), "(D)D")) { - frame->pushLong( + frame->pushDouble( c->unaryOp(lir::FloatSquareRoot, types.f8, frame->popLong())); return true; } else if (MATCH(methodName(t, target), "abs")) { @@ -3787,7 +3835,7 @@ intrinsic(MyThread* t, Frame* frame, object target) frame->pushLong(c->unaryOp(lir::Absolute, types.i8, frame->popLong())); return true; } else if (MATCH(methodSpec(t, target), "(F)F")) { - frame->pushInt( + frame->pushFloat( c->unaryOp(lir::FloatAbsolute, types.f4, frame->popInt())); return true; } @@ -3841,7 +3889,7 @@ intrinsic(MyThread* t, Frame* frame, object target) { ir::Value* address = popLongAddress(frame); frame->popObject(); - frame->pushInt( + frame->pushSmall( c->load(ir::SignExtend, types.i4, c->memory(address, @@ -3868,7 +3916,7 @@ intrinsic(MyThread* t, Frame* frame, object target) { ir::Value* address = popLongAddress(frame); frame->popObject(); - frame->pushLong( + frame->pushLarge( c->load(ir::SignExtend, types.i8, c->memory(address, @@ -4149,13 +4197,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case aaload: frame->pushObject( c->load(ir::SignExtend, - types.address, + types.object, c->memory(array, types.object, TargetArrayBody, index), - types.address)); + types.object)); break; case faload: - frame->pushInt( + frame->pushFloat( c->load(ir::SignExtend, types.f4, c->memory(array, types.f4, TargetArrayBody, index), @@ -4187,7 +4235,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case daload: - frame->pushLong( + frame->pushDouble( c->load(ir::SignExtend, types.f8, c->memory(array, types.f8, TargetArrayBody, index), @@ -4440,7 +4488,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case d2f: { - frame->pushInt(c->f2f(types.f8, types.f4, frame->popLong())); + frame->pushFloat(c->f2f(types.f8, types.f4, frame->popLong())); } break; case d2i: { @@ -4459,7 +4507,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = frame->popLong(); ir::Value* b = frame->popLong(); - frame->pushLong( + frame->pushDouble( c->binaryOp(toCompilerBinaryOp(t, instruction), types.f8, a, b)); } break; @@ -4504,15 +4552,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case dconst_0: - frame->pushLong(c->constant(doubleToBits(0.0), types.f4)); + frame->pushDouble(c->constant(doubleToBits(0.0), types.f4)); break; case dconst_1: - frame->pushLong(c->constant(doubleToBits(1.0), types.f4)); + frame->pushDouble(c->constant(doubleToBits(1.0), types.f4)); break; case dneg: { - frame->pushLong(c->unaryOp(lir::FloatNegate, types.f8, frame->popLong())); + frame->pushDouble( + c->unaryOp(lir::FloatNegate, types.f8, frame->popLong())); } break; case dup: @@ -4540,7 +4589,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case f2d: { - frame->pushLong(c->f2f(types.f4, types.f8, frame->popInt())); + frame->pushDouble(c->f2f(types.f4, types.f8, frame->popInt())); } break; case f2i: { @@ -4559,7 +4608,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = frame->popInt(); ir::Value* b = frame->popInt(); - frame->pushInt( + frame->pushFloat( c->binaryOp(toCompilerBinaryOp(t, instruction), types.f4, a, b)); } break; @@ -4600,19 +4649,19 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case fconst_0: - frame->pushInt(c->constant(floatToBits(0.0), types.f4)); + frame->pushFloat(c->constant(floatToBits(0.0), types.f4)); break; case fconst_1: - frame->pushInt(c->constant(floatToBits(1.0), types.f4)); + frame->pushFloat(c->constant(floatToBits(1.0), types.f4)); break; case fconst_2: - frame->pushInt(c->constant(floatToBits(2.0), types.f4)); + frame->pushFloat(c->constant(floatToBits(2.0), types.f4)); break; case fneg: { - frame->pushInt(c->unaryOp(lir::FloatNegate, types.f4, frame->popInt())); + frame->pushFloat(c->unaryOp(lir::FloatNegate, types.f4, frame->popInt())); } break; case getfield: @@ -4700,7 +4749,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case FloatField: - frame->pushInt(c->load( + frame->pushFloat(c->load( ir::SignExtend, types.f4, c->memory(table, types.f4, targetFieldOffset(context, field)), @@ -4716,7 +4765,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case DoubleField: - frame->pushLong(c->load( + frame->pushDouble(c->load( ir::SignExtend, types.f8, c->memory(table, types.f8, targetFieldOffset(context, field)), @@ -4734,9 +4783,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ObjectField: frame->pushObject(c->load( ir::SignExtend, - types.address, + types.object, c->memory(table, types.object, targetFieldOffset(context, field)), - types.address)); + types.object)); break; default: @@ -4835,11 +4884,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2d: { - frame->pushLong(c->i2f(types.i4, types.f8, frame->popInt())); + frame->pushDouble(c->i2f(types.i4, types.f8, frame->popInt())); } break; case i2f: { - frame->pushInt(c->i2f(types.i4, types.f4, frame->popInt())); + frame->pushFloat(c->i2f(types.i4, types.f4, frame->popInt())); } break; case i2l: @@ -4998,29 +5047,39 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case iload: - case fload: frame->loadInt(codeBody(t, code, ip++)); break; + case fload: + frame->loadFloat(codeBody(t, code, ip++)); + break; case iload_0: - case fload_0: frame->loadInt(0); break; + case fload_0: + frame->loadFloat(0); + break; case iload_1: - case fload_1: frame->loadInt(1); break; + case fload_1: + frame->loadFloat(1); + break; case iload_2: - case fload_2: frame->loadInt(2); break; + case fload_2: + frame->loadFloat(2); + break; case iload_3: - case fload_3: frame->loadInt(3); break; + case fload_3: + frame->loadFloat(3); + break; case ineg: { frame->pushInt(c->unaryOp(lir::Negate, types.i4, frame->popInt())); @@ -5322,11 +5381,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto start; case l2d: { - frame->pushLong(c->i2f(types.i8, types.f8, frame->popLong())); + frame->pushDouble(c->i2f(types.i8, types.f8, frame->popLong())); } break; case l2f: { - frame->pushInt(c->i2f(types.i8, types.f4, frame->popLong())); + frame->pushFloat(c->i2f(types.i8, types.f4, frame->popLong())); } break; case l2i: @@ -5424,7 +5483,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } } } else { - frame->pushInt(c->constant( + frame->pushSmall(c->constant( singletonValue(t, pool, index - 1), singletonBit(t, pool, poolSize(t, pool), index - 1) ? types.f4 : types.i4)); @@ -5438,7 +5497,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint64_t v; memcpy(&v, &singletonValue(t, pool, index - 1), 8); - frame->pushLong(c->constant( + frame->pushLarge(c->constant( v, singletonBit(t, pool, poolSize(t, pool), index - 1) ? types.f8 : types.i8)); @@ -5457,29 +5516,39 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lload: - case dload: frame->loadLong(codeBody(t, code, ip++)); break; + case dload: + frame->loadDouble(codeBody(t, code, ip++)); + break; case lload_0: - case dload_0: frame->loadLong(0); break; + case dload_0: + frame->loadDouble(0); + break; case lload_1: - case dload_1: frame->loadLong(1); break; + case dload_1: + frame->loadDouble(1); + break; case lload_2: - case dload_2: frame->loadLong(2); break; + case dload_2: + frame->loadDouble(2); + break; case lload_3: - case dload_3: frame->loadLong(3); break; + case dload_3: + frame->loadDouble(3); + break; case lneg: frame->pushLong(c->unaryOp(lir::Negate, types.i8, frame->popLong())); @@ -5821,7 +5890,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, value, c->memory(table, types.i2, targetFieldOffset(context, field))); break; - + case FloatField: c->store( types.f4, From 7b0d5774302b723148200ab9c1d40c250ac24cd4 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Fri, 2 May 2014 08:42:41 -0600 Subject: [PATCH 49/89] fix some return type & intrinsic typing --- src/codegen/compiler.cpp | 7 ++++--- src/compile.cpp | 26 ++++++++++---------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index a9d021121e..350835f964 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2667,16 +2667,17 @@ class MyCompiler: public Compiler { ir::Value* src, ir::Type dstType) { - assert(&c, dstType.size() >= TargetBytesPerWord); assert(&c, srcType.flavor() == dstType.flavor()); + assert(&c, src->type.flavor() == dstType.flavor()); - Value* dst = value(&c, src->type); + Value* dst = value(&c, dstType); appendMove(&c, signExtend == ir::SignExtend ? lir::Move : lir::MoveZ, srcType.size(), srcType.size(), static_cast(src), - dstType.size(), + dstType.size() < TargetBytesPerWord ? TargetBytesPerWord + : dstType.size(), dst); return dst; } diff --git a/src/compile.cpp b/src/compile.cpp index 7667018d05..00802fcbdc 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1367,10 +1367,10 @@ ir::Type operandTypeForFieldCode(Thread* t, unsigned code) switch (code) { case ByteField: case BooleanField: - return types.i1; + return types.i4; case CharField: case ShortField: - return types.i2; + return types.i4; case IntField: return types.i4; case LongField: @@ -3889,13 +3889,10 @@ intrinsic(MyThread* t, Frame* frame, object target) { ir::Value* address = popLongAddress(frame); frame->popObject(); + ir::Type type = MATCH(methodName(t, target), "getInt") ? types.i4 + : types.f4; frame->pushSmall( - c->load(ir::SignExtend, - types.i4, - c->memory(address, - MATCH(methodName(t, target), "getInt") ? types.i4 - : types.f4), - types.address)); + c->load(ir::SignExtend, type, c->memory(address, type), type)); return true; } else if ((MATCH(methodName(t, target), "putInt") and MATCH(methodSpec(t, target), "(JI)V")) @@ -3916,13 +3913,10 @@ intrinsic(MyThread* t, Frame* frame, object target) { ir::Value* address = popLongAddress(frame); frame->popObject(); + ir::Type type = MATCH(methodName(t, target), "getLong") ? types.i8 + : types.f8; frame->pushLarge( - c->load(ir::SignExtend, - types.i8, - c->memory(address, - MATCH(methodName(t, target), "getLong") ? types.i8 - : types.f8), - types.i8)); + c->load(ir::SignExtend, type, c->memory(address, type), type)); return true; } else if ((MATCH(methodName(t, target), "putLong") and MATCH(methodSpec(t, target), "(JJ)V")) @@ -4414,7 +4408,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->load(ir::SignExtend, types.address, c->memory(frame->popObject(), types.i4, TargetArrayLength), - types.address)); + types.i4)); } break; case astore: @@ -4753,7 +4747,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::SignExtend, types.f4, c->memory(table, types.f4, targetFieldOffset(context, field)), - types.f8)); + types.f4)); break; case IntField: From 2e40d38078056670dff328f0a682d75b9546456e Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Fri, 2 May 2014 10:05:19 -0600 Subject: [PATCH 50/89] enforce more strong typing in compiler --- src/codegen/compiler.cpp | 19 ++---- src/compile.cpp | 136 ++++++++++++++++++++++++++------------- 2 files changed, 100 insertions(+), 55 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 350835f964..d822db2311 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -1253,15 +1253,6 @@ Value* loadLocal(Context* c, ir::Type type, unsigned index) fprintf(stderr, "load local %p at %d\n", c->locals[index].value, index); } - assert(c, - type.flavor() != ir::Type::Object - || c->locals[index].value->type.flavor() == ir::Type::Object - // TODO: this is a very java-specific hole in the type system. Get - // rid of it: - || c->locals[index].value->type.flavor() == ir::Type::Address - // TODO Temporary hack for Subroutine test!!! - || c->locals[index].value->type.flavor() == ir::Type::Invalid); - return c->locals[index].value; } @@ -2522,7 +2513,10 @@ class MyCompiler: public Compiler { { // TODO: once type information is flowed properly, enable this assert. // Some time later, we can remove the parameter. - // assert(&c, a->type == type); + assert(&c, + a->type == type + // TODO Temporary hack for Subroutine test!!! + || a->type.flavor() == ir::Type::Invalid); appendReturn(&c, type.size(), static_cast(a)); } @@ -2641,7 +2635,8 @@ class MyCompiler: public Compiler { TargetBytesPerWord, truncateType.size(), static_cast(src), - extendType.size(), + extendType.size() < TargetBytesPerWord ? TargetBytesPerWord + : extendType.size(), dst); return dst; } @@ -2724,7 +2719,7 @@ class MyCompiler: public Compiler { (isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b)) or(isFloatBinaryOp(op) and isFloatValue(a) and isFloatValue(b))); - Value* result = value(&c, a->type); + Value* result = value(&c, type); appendCombine(&c, op, diff --git a/src/compile.cpp b/src/compile.cpp index 00802fcbdc..925b182333 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1345,15 +1345,34 @@ ir::Value* loadLocal(Context* context, ir::Type type, unsigned index) { - return context->compiler->loadLocal( + ir::Value* result = context->compiler->loadLocal( type, translateLocalIndex(context, footprint, index)); + + assert(context->thread, + (type.flavor() != ir::Type::Object && type == result->type) + || (type.flavor() == ir::Type::Object + && (result->type.flavor() == ir::Type::Object + || result->type.flavor() == ir::Type::Address)) + // TODO Temporary hack for Subroutine test!!! + || result->type.flavor() == ir::Type::Invalid + || result->type.flavor() == ir::Type::Integer); + return result; } void storeLocal(Context* context, unsigned footprint, + ir::Type type UNUSED, ir::Value* value, unsigned index) { + assert(context->thread, + (type.flavor() != ir::Type::Object && type == value->type) + || (type.flavor() == ir::Type::Object + && (value->type.flavor() == ir::Type::Object + || value->type.flavor() == ir::Type::Address)) + // TODO Temporary hack for Subroutine test!!! + || value->type.flavor() == ir::Type::Invalid + || value->type.flavor() == ir::Type::Integer); context->compiler->storeLocal (footprint, value, translateLocalIndex(context, footprint, index)); } @@ -1783,15 +1802,15 @@ class Frame { void pushInt(ir::Value* o) { assert(t, - o->type.flavor() == ir::Type::Integer - // TODO Temporary hack for Subroutine test!!! + o->type == types.i4 + // TODO Temporary hack for Subroutine test!!! || o->type.flavor() == ir::Type::Invalid); pushSmall(o); } void pushFloat(ir::Value* o) { - assert(t, o->type.flavor() == ir::Type::Float); + assert(t, o->type == types.f4); pushSmall(o); } @@ -1827,15 +1846,15 @@ class Frame { void pushLong(ir::Value* o) { assert(t, - o->type.flavor() == ir::Type::Integer - // TODO Temporary hack for Subroutine test!!! + o->type == types.i8 + // TODO Temporary hack for Subroutine test!!! || o->type.flavor() == ir::Type::Invalid); pushLarge(o); } void pushDouble(ir::Value* o) { - assert(t, o->type.flavor() == ir::Type::Float); + assert(t, o->type == types.f8); pushLarge(o); } @@ -1890,22 +1909,34 @@ class Frame { } void storeInt(unsigned index) { - storeLocal(context, 1, popInt(), index); + storeLocal(context, 1, types.i4, popInt(), index); + storedInt(translateLocalIndex(context, 1, index)); + } + + void storeFloat(unsigned index) + { + storeLocal(context, 1, types.f4, popInt(), index); storedInt(translateLocalIndex(context, 1, index)); } void storeLong(unsigned index) { - storeLocal(context, 2, popLong(), index); + storeLocal(context, 2, types.i8, popLong(), index); + storedLong(translateLocalIndex(context, 2, index)); + } + + void storeDouble(unsigned index) + { + storeLocal(context, 2, types.f8, popLong(), index); storedLong(translateLocalIndex(context, 2, index)); } void storeObject(unsigned index) { - storeLocal(context, 1, popObject(), index); + storeLocal(context, 1, types.object, popObject(), index); storedObject(translateLocalIndex(context, 1, index)); } void storeObjectOrAddress(unsigned index) { - storeLocal(context, 1, popQuiet(types.i4), index); + storeLocal(context, 1, types.object, popQuiet(types.object), index); assert(t, sp >= 1); assert(t, sp - 1 >= localSize()); @@ -3534,6 +3565,7 @@ handleEntrance(MyThread* t, Frame* frame) unsigned index = savedTargetIndex(t, method); storeLocal(frame->context, 1, + frame->types.object, loadLocal(frame->context, 1, frame->types.object, 0), index); frame->set(index, Frame::Object); @@ -3847,10 +3879,8 @@ intrinsic(MyThread* t, Frame* frame, object target) { ir::Value* address = popLongAddress(frame); frame->popObject(); - frame->pushInt(c->load(ir::SignExtend, - types.i1, - c->memory(address, types.i1), - types.address)); + frame->pushInt(c->load( + ir::SignExtend, types.i1, c->memory(address, types.i1), types.i4)); return true; } else if (MATCH(methodName(t, target), "putByte") and MATCH(methodSpec(t, target), "(JB)V")) @@ -3867,10 +3897,8 @@ intrinsic(MyThread* t, Frame* frame, object target) { ir::Value* address = popLongAddress(frame); frame->popObject(); - frame->pushInt(c->load(ir::SignExtend, - types.i2, - c->memory(address, types.i2), - types.address)); + frame->pushInt(c->load( + ir::SignExtend, types.i2, c->memory(address, types.i2), types.i4)); return true; } else if ((MATCH(methodName(t, target), "putShort") and MATCH(methodSpec(t, target), "(JS)V")) @@ -4201,7 +4229,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->load(ir::SignExtend, types.f4, c->memory(array, types.f4, TargetArrayBody, index), - types.f8)); + types.f4)); break; case iaload: @@ -4209,7 +4237,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->load(ir::SignExtend, types.i4, c->memory(array, types.i4, TargetArrayBody, index), - types.address)); + types.i4)); break; case baload: @@ -4217,7 +4245,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->load(ir::SignExtend, types.i1, c->memory(array, types.i1, TargetArrayBody, index), - types.address)); + types.i4)); break; case caload: @@ -4225,7 +4253,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->load(ir::ZeroExtend, types.i2, c->memory(array, types.i2, TargetArrayBody, index), - types.address)); + types.i4)); break; case daload: @@ -4249,7 +4277,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->load(ir::SignExtend, types.i2, c->memory(array, types.i2, TargetArrayBody, index), - types.address)); + types.i4)); break; } } break; @@ -4546,11 +4574,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case dconst_0: - frame->pushDouble(c->constant(doubleToBits(0.0), types.f4)); + frame->pushDouble(c->constant(doubleToBits(0.0), types.f8)); break; case dconst_1: - frame->pushDouble(c->constant(doubleToBits(1.0), types.f4)); + frame->pushDouble(c->constant(doubleToBits(1.0), types.f8)); break; case dneg: { @@ -4723,7 +4751,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::SignExtend, types.i1, c->memory(table, types.i4, targetFieldOffset(context, field)), - types.address)); + types.i4)); break; case CharField: @@ -4731,7 +4759,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::ZeroExtend, types.i2, c->memory(table, types.i4, targetFieldOffset(context, field)), - types.address)); + types.i4)); break; case ShortField: @@ -4739,7 +4767,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::SignExtend, types.i2, c->memory(table, types.i4, targetFieldOffset(context, field)), - types.address)); + types.i4)); break; case FloatField: @@ -4755,7 +4783,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::SignExtend, types.i4, c->memory(table, types.i4, targetFieldOffset(context, field)), - types.address)); + types.i4)); break; case DoubleField: @@ -4869,12 +4897,12 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case i2b: { frame->pushInt(c->truncateThenExtend( - ir::SignExtend, types.address, types.i1, frame->popInt())); + ir::SignExtend, types.i4, types.i1, frame->popInt())); } break; case i2c: { frame->pushInt(c->truncateThenExtend( - ir::ZeroExtend, types.address, types.i2, frame->popInt())); + ir::ZeroExtend, types.i4, types.i2, frame->popInt())); } break; case i2d: { @@ -4892,7 +4920,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case i2s: { frame->pushInt(c->truncateThenExtend( - ir::SignExtend, types.address, types.i2, frame->popInt())); + ir::SignExtend, types.i4, types.i2, frame->popInt())); } break; case iadd: @@ -5033,6 +5061,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, storeLocal(context, 1, + types.i4, c->binaryOp(lir::Add, types.i4, c->constant(count, types.i4), @@ -5324,29 +5353,39 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto next; case istore: - case fstore: frame->storeInt(codeBody(t, code, ip++)); break; + case fstore: + frame->storeFloat(codeBody(t, code, ip++)); + break; case istore_0: - case fstore_0: frame->storeInt(0); break; + case fstore_0: + frame->storeFloat(0); + break; case istore_1: - case fstore_1: frame->storeInt(1); break; + case fstore_1: + frame->storeFloat(1); + break; case istore_2: - case fstore_2: frame->storeInt(2); break; + case fstore_2: + frame->storeFloat(2); + break; case istore_3: - case fstore_3: frame->storeInt(3); break; + case fstore_3: + frame->storeFloat(3); + break; case jsr: case jsr_w: { @@ -5648,29 +5687,39 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lstore: - case dstore: frame->storeLong(codeBody(t, code, ip++)); break; + case dstore: + frame->storeDouble(codeBody(t, code, ip++)); + break; case lstore_0: - case dstore_0: frame->storeLong(0); break; + case dstore_0: + frame->storeDouble(0); + break; case lstore_1: - case dstore_1: frame->storeLong(1); break; + case dstore_1: + frame->storeDouble(1); + break; case lstore_2: - case dstore_2: frame->storeLong(2); break; + case dstore_2: + frame->storeDouble(2); + break; case lstore_3: - case dstore_3: frame->storeLong(3); break; + case dstore_3: + frame->storeDouble(3); + break; case monitorenter: { ir::Value* target = frame->popObject(); @@ -6152,6 +6201,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, storeLocal(context, 1, + types.i4, c->binaryOp(lir::Add, types.i4, c->constant(count, types.i4), From 781977d19c473e62aecb8f6656e2d3eb1a8fff61 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 19:32:40 -0600 Subject: [PATCH 51/89] add debug-util for printing java bytecode as it's compiled --- makefile | 1 + src/compile.cpp | 31 ++- src/debug-util.cpp | 620 +++++++++++++++++++++++++++++++++++++++++++++ src/debug-util.h | 24 ++ 4 files changed, 675 insertions(+), 1 deletion(-) create mode 100644 src/debug-util.cpp create mode 100644 src/debug-util.h diff --git a/makefile b/makefile index 0f768ac8fd..07633f834f 100755 --- a/makefile +++ b/makefile @@ -1125,6 +1125,7 @@ embed-objects = $(call cpp-objects,$(embed-sources),$(src),$(build-embed)) compiler-sources = \ $(src)/codegen/compiler.cpp \ $(wildcard $(src)/codegen/compiler/*.cpp) \ + $(src)/debug-util.cpp \ $(src)/codegen/registers.cpp \ $(src)/codegen/runtime.cpp \ $(src)/codegen/targets.cpp \ diff --git a/src/compile.cpp b/src/compile.cpp index 925b182333..03fb7e070c 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -27,6 +27,8 @@ #include #include +#include "debug-util.h" + using namespace vm; extern "C" uint64_t @@ -56,6 +58,7 @@ const bool DebugNatives = false; const bool DebugCallTable = false; const bool DebugMethodTree = false; const bool DebugFrameMaps = false; +const bool DebugInstructions = false; const bool CheckArrayBounds = true; @@ -4189,9 +4192,35 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, 1, c->threadRegister()); } - + // fprintf(stderr, "ip: %d map: %ld\n", ip, *(frame->map)); + if (DebugInstructions) { + unsigned startingIp = ip; + // TODO: fix stack printing + fprintf(stderr, " stack: ["); + for (size_t i = frame->localSize(); i < frame->sp; i++) { + switch (frame->get(i)) { + case Frame::Integer: + fprintf(stderr, "I"); + break; + case Frame::Long: + fprintf(stderr, "L"); + break; + case Frame::Object: + fprintf(stderr, "O"); + break; + default: + fprintf(stderr, "?"); + break; + } + } + fprintf(stderr, "]\n"); + fprintf(stderr, "% 5d: ", startingIp); + avian::jvm::debug::printInstruction(&codeBody(t, code, 0), startingIp); + fprintf(stderr, "\n"); + } + unsigned instruction = codeBody(t, code, ip++); switch (instruction) { diff --git a/src/debug-util.cpp b/src/debug-util.cpp new file mode 100644 index 0000000000..03a3c9540e --- /dev/null +++ b/src/debug-util.cpp @@ -0,0 +1,620 @@ +/* Copyright (c) 2008-2013, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#include + +#include "debug-util.h" + +namespace avian { +namespace jvm { +namespace debug { + +uint16_t read16(uint8_t* code, unsigned& ip) +{ + uint16_t a = code[ip++]; + uint16_t b = code[ip++]; + return (a << 8) | b; +} + +uint32_t read32(uint8_t* code, unsigned& ip) +{ + uint32_t b = code[ip++]; + uint32_t a = code[ip++]; + uint32_t c = code[ip++]; + uint32_t d = code[ip++]; + return (a << 24) | (b << 16) | (c << 8) | d; +} + +using namespace vm; + +int printInstruction(uint8_t* code, unsigned& ip, const char* prefix) +{ + unsigned startIp = ip; + + uint8_t instr = code[ip++]; + switch (instr) { + case aaload: + return fprintf(stderr, "aaload"); + case aastore: + return fprintf(stderr, "aastore"); + + case aconst_null: + return fprintf(stderr, "aconst_null"); + + case aload: + return fprintf(stderr, "aload %2d", code[ip++]); + case aload_0: + return fprintf(stderr, "aload_0"); + case aload_1: + return fprintf(stderr, "aload_1"); + case aload_2: + return fprintf(stderr, "aload_2"); + case aload_3: + return fprintf(stderr, "aload_3"); + + case anewarray: + return fprintf(stderr, "anewarray %4d", read16(code, ip)); + case areturn: + return fprintf(stderr, "areturn"); + case arraylength: + return fprintf(stderr, "arraylength"); + + case astore: + return fprintf(stderr, "astore %2d", code[ip++]); + case astore_0: + return fprintf(stderr, "astore_0"); + case astore_1: + return fprintf(stderr, "astore_1"); + case astore_2: + return fprintf(stderr, "astore_2"); + case astore_3: + return fprintf(stderr, "astore_3"); + + case athrow: + return fprintf(stderr, "athrow"); + case baload: + return fprintf(stderr, "baload"); + case bastore: + return fprintf(stderr, "bastore"); + + case bipush: + return fprintf(stderr, "bipush %2d", code[ip++]); + case caload: + return fprintf(stderr, "caload"); + case castore: + return fprintf(stderr, "castore"); + case checkcast: + return fprintf(stderr, "checkcast %4d", read16(code, ip)); + case d2f: + return fprintf(stderr, "d2f"); + case d2i: + return fprintf(stderr, "d2i"); + case d2l: + return fprintf(stderr, "d2l"); + case dadd: + return fprintf(stderr, "dadd"); + case daload: + return fprintf(stderr, "daload"); + case dastore: + return fprintf(stderr, "dastore"); + case dcmpg: + return fprintf(stderr, "dcmpg"); + case dcmpl: + return fprintf(stderr, "dcmpl"); + case dconst_0: + return fprintf(stderr, "dconst_0"); + case dconst_1: + return fprintf(stderr, "dconst_1"); + case ddiv: + return fprintf(stderr, "ddiv"); + case dmul: + return fprintf(stderr, "dmul"); + case dneg: + return fprintf(stderr, "dneg"); + case vm::drem: + return fprintf(stderr, "drem"); + case dsub: + return fprintf(stderr, "dsub"); + case dup: + return fprintf(stderr, "dup"); + case dup_x1: + return fprintf(stderr, "dup_x1"); + case dup_x2: + return fprintf(stderr, "dup_x2"); + case dup2: + return fprintf(stderr, "dup2"); + case dup2_x1: + return fprintf(stderr, "dup2_x1"); + case dup2_x2: + return fprintf(stderr, "dup2_x2"); + case f2d: + return fprintf(stderr, "f2d"); + case f2i: + return fprintf(stderr, "f2i"); + case f2l: + return fprintf(stderr, "f2l"); + case fadd: + return fprintf(stderr, "fadd"); + case faload: + return fprintf(stderr, "faload"); + case fastore: + return fprintf(stderr, "fastore"); + case fcmpg: + return fprintf(stderr, "fcmpg"); + case fcmpl: + return fprintf(stderr, "fcmpl"); + case fconst_0: + return fprintf(stderr, "fconst_0"); + case fconst_1: + return fprintf(stderr, "fconst_1"); + case fconst_2: + return fprintf(stderr, "fconst_2"); + case fdiv: + return fprintf(stderr, "fdiv"); + case fmul: + return fprintf(stderr, "fmul"); + case fneg: + return fprintf(stderr, "fneg"); + case frem: + return fprintf(stderr, "frem"); + case fsub: + return fprintf(stderr, "fsub"); + + case getfield: + return fprintf(stderr, "getfield %4d", read16(code, ip)); + case getstatic: + return fprintf(stderr, "getstatic %4d", read16(code, ip)); + case goto_: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "goto %4d", offset + ip - 3); + } + case goto_w: { + int32_t offset = read32(code, ip); + return fprintf(stderr, "goto_w %08x", offset + ip - 5); + } + + case i2b: + return fprintf(stderr, "i2b"); + case i2c: + return fprintf(stderr, "i2c"); + case i2d: + return fprintf(stderr, "i2d"); + case i2f: + return fprintf(stderr, "i2f"); + case i2l: + return fprintf(stderr, "i2l"); + case i2s: + return fprintf(stderr, "i2s"); + case iadd: + return fprintf(stderr, "iadd"); + case iaload: + return fprintf(stderr, "iaload"); + case iand: + return fprintf(stderr, "iand"); + case iastore: + return fprintf(stderr, "iastore"); + case iconst_m1: + return fprintf(stderr, "iconst_m1"); + case iconst_0: + return fprintf(stderr, "iconst_0"); + case iconst_1: + return fprintf(stderr, "iconst_1"); + case iconst_2: + return fprintf(stderr, "iconst_2"); + case iconst_3: + return fprintf(stderr, "iconst_3"); + case iconst_4: + return fprintf(stderr, "iconst_4"); + case iconst_5: + return fprintf(stderr, "iconst_5"); + case idiv: + return fprintf(stderr, "idiv"); + + case if_acmpeq: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "if_acmpeq %4d", offset + ip - 3); + } + case if_acmpne: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "if_acmpne %4d", offset + ip - 3); + } + case if_icmpeq: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "if_icmpeq %4d", offset + ip - 3); + } + case if_icmpne: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "if_icmpne %4d", offset + ip - 3); + } + + case if_icmpgt: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "if_icmpgt %4d", offset + ip - 3); + } + case if_icmpge: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "if_icmpge %4d", offset + ip - 3); + } + case if_icmplt: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "if_icmplt %4d", offset + ip - 3); + } + case if_icmple: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "if_icmple %4d", offset + ip - 3); + } + + case ifeq: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "ifeq %4d", offset + ip - 3); + } + case ifne: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "ifne %4d", offset + ip - 3); + } + case ifgt: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "ifgt %4d", offset + ip - 3); + } + case ifge: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "ifge %4d", offset + ip - 3); + } + case iflt: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "iflt %4d", offset + ip - 3); + } + case ifle: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "ifle %4d", offset + ip - 3); + } + + case ifnonnull: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "ifnonnull %4d", offset + ip - 3); + } + case ifnull: { + int16_t offset = read16(code, ip); + return fprintf(stderr, "ifnull %4d", offset + ip - 3); + } + + case iinc: { + uint8_t a = code[ip++]; + uint8_t b = code[ip++]; + return fprintf(stderr, "iinc %2d %2d", a, b); + } + + case iload: + return fprintf(stderr, "iload %2d", code[ip++]); + case fload: + return fprintf(stderr, "fload %2d", code[ip++]); + + case iload_0: + return fprintf(stderr, "iload_0"); + case fload_0: + return fprintf(stderr, "fload_0"); + case iload_1: + return fprintf(stderr, "iload_1"); + case fload_1: + return fprintf(stderr, "fload_1"); + + case iload_2: + return fprintf(stderr, "iload_2"); + case fload_2: + return fprintf(stderr, "fload_2"); + case iload_3: + return fprintf(stderr, "iload_3"); + case fload_3: + return fprintf(stderr, "fload_3"); + + case imul: + return fprintf(stderr, "imul"); + case ineg: + return fprintf(stderr, "ineg"); + + case instanceof: + return fprintf(stderr, "instanceof %4d", read16(code, ip)); + case invokeinterface: + return fprintf(stderr, "invokeinterface %4d", read16(code, ip)); + case invokespecial: + return fprintf(stderr, "invokespecial %4d", read16(code, ip)); + case invokestatic: + return fprintf(stderr, "invokestatic %4d", read16(code, ip)); + case invokevirtual: + return fprintf(stderr, "invokevirtual %4d", read16(code, ip)); + + case ior: + return fprintf(stderr, "ior"); + case irem: + return fprintf(stderr, "irem"); + case ireturn: + return fprintf(stderr, "ireturn"); + case freturn: + return fprintf(stderr, "freturn"); + case ishl: + return fprintf(stderr, "ishl"); + case ishr: + return fprintf(stderr, "ishr"); + + case istore: + return fprintf(stderr, "istore %2d", code[ip++]); + case fstore: + return fprintf(stderr, "fstore %2d", code[ip++]); + + case istore_0: + return fprintf(stderr, "istore_0"); + case fstore_0: + return fprintf(stderr, "fstore_0"); + case istore_1: + return fprintf(stderr, "istore_1"); + case fstore_1: + return fprintf(stderr, "fstore_1"); + case istore_2: + return fprintf(stderr, "istore_2"); + case fstore_2: + return fprintf(stderr, "fstore_2"); + case istore_3: + return fprintf(stderr, "istore_3"); + case fstore_3: + return fprintf(stderr, "fstore_3"); + + case isub: + return fprintf(stderr, "isub"); + case iushr: + return fprintf(stderr, "iushr"); + case ixor: + return fprintf(stderr, "ixor"); + + case jsr: + return fprintf(stderr, "jsr %4d", read16(code, ip) + startIp); + case jsr_w: + return fprintf(stderr, "jsr_w %08x", read32(code, ip) + startIp); + + case l2d: + return fprintf(stderr, "l2d"); + case l2f: + return fprintf(stderr, "l2f"); + case l2i: + return fprintf(stderr, "l2i"); + case ladd: + return fprintf(stderr, "ladd"); + case laload: + return fprintf(stderr, "laload"); + + case land: + return fprintf(stderr, "land"); + case lastore: + return fprintf(stderr, "lastore"); + + case lcmp: + return fprintf(stderr, "lcmp"); + case lconst_0: + return fprintf(stderr, "lconst_0"); + case lconst_1: + return fprintf(stderr, "lconst_1"); + + case ldc: + return fprintf(stderr, "ldc %4d", read16(code, ip)); + case ldc_w: + return fprintf(stderr, "ldc_w %08x", read32(code, ip)); + case ldc2_w: + return fprintf(stderr, "ldc2_w %4d", read16(code, ip)); + + case ldiv_: + return fprintf(stderr, "ldiv_"); + + case lload: + return fprintf(stderr, "lload %2d", code[ip++]); + case dload: + return fprintf(stderr, "dload %2d", code[ip++]); + + case lload_0: + return fprintf(stderr, "lload_0"); + case dload_0: + return fprintf(stderr, "dload_0"); + case lload_1: + return fprintf(stderr, "lload_1"); + case dload_1: + return fprintf(stderr, "dload_1"); + case lload_2: + return fprintf(stderr, "lload_2"); + case dload_2: + return fprintf(stderr, "dload_2"); + case lload_3: + return fprintf(stderr, "lload_3"); + case dload_3: + return fprintf(stderr, "dload_3"); + + case lmul: + return fprintf(stderr, "lmul"); + case lneg: + return fprintf(stderr, "lneg"); + + case lookupswitch: { + while (ip & 0x3) { + ip++; + } + int32_t default_ = read32(code, ip) + startIp; + int32_t pairCount = read32(code, ip); + fprintf( + stderr, "lookupswitch default: %d pairCount: %d", default_, pairCount); + + bool good = true; + if (pairCount >= 1000) { + pairCount = 1; + good = false; + } + + for (int i = 0; i < pairCount; i++) { + int32_t k = read32(code, ip); + int32_t d = read32(code, ip) + startIp; + fprintf(stderr, "\n%s key: %2d dest: %d", prefix, k, d); + } + fprintf(stderr, "\n"); + fflush(stderr); + if (!good) + asm("int3"); + return 0; + } + + case lor: + return fprintf(stderr, "lor"); + case lrem: + return fprintf(stderr, "lrem"); + case lreturn: + return fprintf(stderr, "lreturn"); + case dreturn: + return fprintf(stderr, "dreturn"); + case lshl: + return fprintf(stderr, "lshl"); + case lshr: + return fprintf(stderr, "lshr"); + + case lstore: + return fprintf(stderr, "lstore %2d", code[ip++]); + case dstore: + return fprintf(stderr, "dstore %2d", code[ip++]); + + case lstore_0: + return fprintf(stderr, "lstore_0"); + case dstore_0: + return fprintf(stderr, "dstore_0"); + case lstore_1: + return fprintf(stderr, "lstore_1"); + case dstore_1: + return fprintf(stderr, "dstore_1"); + case lstore_2: + return fprintf(stderr, "lstore_2"); + case dstore_2: + return fprintf(stderr, "dstore_2"); + case lstore_3: + return fprintf(stderr, "lstore_3"); + case dstore_3: + return fprintf(stderr, "dstore_3"); + + case lsub: + return fprintf(stderr, "lsub"); + case lushr: + return fprintf(stderr, "lushr"); + case lxor: + return fprintf(stderr, "lxor"); + + case monitorenter: + return fprintf(stderr, "monitorenter"); + case monitorexit: + return fprintf(stderr, "monitorexit"); + + case multianewarray: { + unsigned type = read16(code, ip); + return fprintf(stderr, "multianewarray %4d %2d", type, code[ip++]); + } + + case new_: + return fprintf(stderr, "new %4d", read16(code, ip)); + + case newarray: + return fprintf(stderr, "newarray %2d", code[ip++]); + + case nop: + return fprintf(stderr, "nop"); + case pop_: + return fprintf(stderr, "pop"); + case pop2: + return fprintf(stderr, "pop2"); + + case putfield: + return fprintf(stderr, "putfield %4d", read16(code, ip)); + case putstatic: + return fprintf(stderr, "putstatic %4d", read16(code, ip)); + + case ret: + return fprintf(stderr, "ret %2d", code[ip++]); + + case return_: + return fprintf(stderr, "return_"); + case saload: + return fprintf(stderr, "saload"); + case sastore: + return fprintf(stderr, "sastore"); + + case sipush: + return fprintf(stderr, "sipush %4d", read16(code, ip)); + + case swap: + return fprintf(stderr, "swap"); + + case tableswitch: { + while (ip & 0x3) { + ip++; + } + int32_t default_ = read32(code, ip) + startIp; + int32_t bottom = read32(code, ip); + int32_t top = read32(code, ip); + fprintf(stderr, + "tableswitch default: %d bottom: %d top: %d", + default_, + bottom, + top); + + for (int i = 0; i < top - bottom + 1; i++) { + int32_t d = read32(code, ip) + startIp; + fprintf(stderr, "%s key: %d dest: %d", prefix, i + bottom, d); + } + return 0; + } + + case wide: { + switch (code[ip++]) { + case aload: + return fprintf(stderr, "wide aload %4d", read16(code, ip)); + + case astore: + return fprintf(stderr, "wide astore %4d", read16(code, ip)); + case iinc: + fprintf(stderr, "wide iinc %4d %4d", read16(code, ip), read16(code, ip)); + case iload: + return fprintf(stderr, "wide iload %4d", read16(code, ip)); + case istore: + return fprintf(stderr, "wide istore %4d", read16(code, ip)); + case lload: + return fprintf(stderr, "wide lload %4d", read16(code, ip)); + case lstore: + return fprintf(stderr, "wide lstore %4d", read16(code, ip)); + case ret: + return fprintf(stderr, "wide ret %4d", read16(code, ip)); + + default: { + fprintf( + stderr, "unknown wide instruction %2d %4d", instr, read16(code, ip)); + } + } + } + + default: { + return fprintf(stderr, "unknown instruction %2d", instr); + } + } + return ip; +} + +void disassembleCode(const char* prefix, uint8_t* code, unsigned length) +{ + unsigned ip = 0; + + while (ip < length) { + fprintf(stderr, "%s%x:\t", prefix, ip); + printInstruction(code, ip, prefix); + fprintf(stderr, "\n"); + } +} + +} // namespace debug +} // namespace jvm +} // namespace avian diff --git a/src/debug-util.h b/src/debug-util.h new file mode 100644 index 0000000000..bb981baa10 --- /dev/null +++ b/src/debug-util.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2008-2013, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#include + +namespace avian { +namespace jvm { +namespace debug { + +// print out a single instruction (no newline) +// returns number of characters printed +int printInstruction(uint8_t* code, unsigned& ip, const char* prefix = ""); +void disassembleCode(const char* prefix, uint8_t* code, unsigned length); + +} // namespace debug +} // namespace jvm +} // namespace avian From 14c960ac6a17ba4ba4d30d06eedec4ae19933ad0 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 19:01:08 -0600 Subject: [PATCH 52/89] improve Slice --- include/avian/util/assert.h | 32 ++++++++++++++++++++++++++++++++ include/avian/util/slice.h | 34 ++++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 include/avian/util/assert.h diff --git a/include/avian/util/assert.h b/include/avian/util/assert.h new file mode 100644 index 0000000000..ab6cee63ed --- /dev/null +++ b/include/avian/util/assert.h @@ -0,0 +1,32 @@ +/* Copyright (c) 2008-2013, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#ifndef AVIAN_UTIL_ASSERT_H +#define AVIAN_UTIL_ASSERT_H + +#include + +namespace avian { +namespace util { + +#define UNREACHABLE_ ::abort() + +// TODO: print msg in debug mode +#define UNREACHABLE(msg) ::abort() + +#define ASSERT(that) \ + if (!(that)) { \ + UNREACHABLE(#that); \ + } + +} // namespace util +} // namespace avian + +#endif // AVIAN_UTIL_ASSERT_H diff --git a/include/avian/util/slice.h b/include/avian/util/slice.h index b4936e0a06..51b1ad918e 100644 --- a/include/avian/util/slice.h +++ b/include/avian/util/slice.h @@ -13,6 +13,7 @@ #include "allocator.h" #include "math.h" +#include "assert.h" namespace avian { namespace util { @@ -33,6 +34,7 @@ class Slice { inline T& operator[](size_t index) { + ASSERT(index < count); return items[index]; } @@ -51,20 +53,36 @@ class Slice { return Slice((T*)a->allocate(sizeof(T) * count), count); } - Slice clone(Allocator* a) + static Slice allocAndSet(Allocator* a, size_t count, const T& item) { - Slice ret((T*)a->allocate(count * sizeof(T)), count); - memcpy(ret.items, items, count * sizeof(T)); - return ret; + Slice slice(alloc(a, count)); + for (size_t i = 0; i < count; i++) { + slice[i] = item; + } + return slice; + } + + Slice clone(Allocator* a, size_t newCount) + { + T* newItems = (T*)a->allocate(newCount * sizeof(T)); + memcpy(newItems, items, min(count, newCount) * sizeof(T)); + return Slice(newItems, newCount); + } + + Slice cloneAndSet(Allocator* a, size_t newCount, const T& item) + { + Slice slice(clone(a, newCount)); + for (size_t i = count; i < newCount; i++) { + slice[i] = item; + } + return slice; } void resize(Allocator* a, size_t newCount) { - T* newItems = (T*)a->allocate(newCount * sizeof(T)); - memcpy(newItems, items, min(count, newCount)); + Slice slice(clone(a, newCount)); a->free(items, count); - items = newItems; - count = newCount; + *this = slice; } }; From 5ad1a14a736c82059048096dca4b5a8956ee7012 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 19:09:55 -0600 Subject: [PATCH 53/89] explode Subroutines in compile.cpp rather than handling them in Compiler --- include/avian/codegen/compiler.h | 10 +- src/codegen/compiler.cpp | 74 +-- src/codegen/compiler/context.cpp | 3 - src/codegen/compiler/context.h | 47 +- src/codegen/compiler/ir.cpp | 13 +- src/codegen/compiler/ir.h | 8 - src/compile.cpp | 960 +++++++++++-------------------- 7 files changed, 391 insertions(+), 724 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 109d8891f8..d4290cbe63 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -42,19 +42,15 @@ class Compiler { static const unsigned LongJumpOrCall = 1 << 3; class State { }; - class Subroutine { }; virtual State* saveState() = 0; virtual void restoreState(State* state) = 0; - virtual Subroutine* startSubroutine() = 0; - virtual void returnFromSubroutine(Subroutine* subroutine, ir::Value* address) - = 0; - virtual void linkSubroutine(Subroutine* subroutine) = 0; - virtual void init(unsigned logicalCodeSize, unsigned parameterFootprint, unsigned localFootprint, unsigned alignedFrameSize) = 0; + virtual void extendLogicalCode(unsigned more) = 0; + virtual void visitLogicalIp(unsigned logicalIp) = 0; virtual void startLogicalIp(unsigned logicalIp) = 0; @@ -76,7 +72,7 @@ class Compiler { virtual void push(ir::Type type, ir::Value* value) = 0; virtual void save(ir::Type type, ir::Value* value) = 0; virtual ir::Value* pop(ir::Type type) = 0; - virtual void pushed() = 0; + virtual void pushed(ir::Type type) = 0; virtual void popped(unsigned footprint) = 0; virtual unsigned topOfStack() = 0; virtual ir::Value* peek(unsigned footprint, unsigned index) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index d822db2311..d1dafc2a0e 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2141,27 +2141,9 @@ class MyCompiler: public Compiler { compiler::restoreState(&c, static_cast(state)); } - virtual Subroutine* startSubroutine() { - return c.subroutine = new(c.zone) MySubroutine; - } - - virtual void returnFromSubroutine(Subroutine* subroutine, ir::Value* address) - { - appendSaveLocals(&c); - appendJump(&c, lir::Jump, static_cast(address), false, true); - static_cast(subroutine)->forkState = compiler::saveState(&c); - } - - virtual void linkSubroutine(Subroutine* subroutine) { - Local* oldLocals = c.locals; - restoreState(static_cast(subroutine)->forkState); - linkLocals(&c, oldLocals, c.locals); - } - virtual void init(unsigned logicalCodeLength, unsigned parameterFootprint, unsigned localFootprint, unsigned alignedFrameSize) { - c.logicalCodeLength = logicalCodeLength; c.parameterFootprint = parameterFootprint; c.localFootprint = localFootprint; c.alignedFrameSize = alignedFrameSize; @@ -2180,23 +2162,23 @@ class MyCompiler: public Compiler { c.frameResources[base + c.arch->framePointerOffset()].reserved = UseFramePointer; - // leave room for logical instruction -1 - unsigned codeSize = sizeof(LogicalInstruction*) * (logicalCodeLength + 1); - c.logicalCode = static_cast - (c.zone->allocate(codeSize)); - memset(c.logicalCode, 0, codeSize); - c.logicalCode++; + c.logicalCode.init(c.zone, logicalCodeLength); + + c.logicalCode[-1] = new (c.zone) LogicalInstruction(-1, c.stack, c.locals); c.locals = static_cast (c.zone->allocate(sizeof(Local) * localFootprint)); memset(c.locals, 0, sizeof(Local) * localFootprint); + } - c.logicalCode[-1] = new(c.zone) LogicalInstruction(-1, c.stack, c.locals); + virtual void extendLogicalCode(unsigned more) + { + c.logicalCode.extend(c.zone, more); } virtual void visitLogicalIp(unsigned logicalIp) { - assert(&c, logicalIp < c.logicalCodeLength); + assert(&c, logicalIp < c.logicalCode.count()); if (c.logicalCode[c.logicalIp]->lastEvent == 0) { appendDummy(&c); @@ -2228,17 +2210,11 @@ class MyCompiler: public Compiler { populateJunctionReads(&c, link); } - if (c.subroutine) { - c.subroutine->forkState - = c.logicalCode[logicalIp]->subroutine->forkState; - c.subroutine = 0; - } - c.forkState = 0; } virtual void startLogicalIp(unsigned logicalIp) { - assert(&c, logicalIp < c.logicalCodeLength); + assert(&c, logicalIp < c.logicalCode.count()); assert(&c, c.logicalCode[logicalIp] == 0); if (c.logicalCode[c.logicalIp]->lastEvent == 0) { @@ -2253,30 +2229,7 @@ class MyCompiler: public Compiler { c.logicalCode[logicalIp] = new(c.zone) LogicalInstruction(logicalIp, c.stack, c.locals); - bool startSubroutine = c.subroutine != 0; - if (startSubroutine) { - c.logicalCode[logicalIp]->subroutine = c.subroutine; - c.subroutine = 0; - } - c.logicalIp = logicalIp; - - if (startSubroutine) { - // assume all local variables are initialized on entry to a - // subroutine, since other calls to the subroutine may - // initialize them: - unsigned sizeInBytes = sizeof(Local) * c.localFootprint; - Local* newLocals = static_cast(c.zone->allocate(sizeInBytes)); - memcpy(newLocals, c.locals, sizeInBytes); - c.locals = newLocals; - - for (unsigned li = 0; li < c.localFootprint; ++li) { - Local* local = c.locals + li; - if (local->value == 0) { - initLocal(1, li, ir::Type(ir::Type::Invalid, TargetBytesPerWord)); - } - } - } } virtual Promise* machineIp(unsigned logicalIp) { @@ -2377,8 +2330,9 @@ class MyCompiler: public Compiler { return value; } - virtual void pushed() { - Value* v = value(&c, ir::Type(ir::Type::Object, TargetBytesPerWord)); + virtual void pushed(ir::Type type) + { + Value* v = value(&c, type); appendFrameSite (&c, v, frameIndex (&c, (c.stack ? c.stack->index : 0) + c.localFootprint)); @@ -2570,7 +2524,7 @@ class MyCompiler: public Compiler { } virtual void initLocalsFromLogicalIp(unsigned logicalIp) { - assert(&c, logicalIp < c.logicalCodeLength); + assert(&c, logicalIp < c.logicalCode.count()); unsigned footprint = sizeof(Local) * c.localFootprint; Local* newLocals = static_cast(c.zone->allocate(footprint)); @@ -2599,7 +2553,9 @@ class MyCompiler: public Compiler { } virtual void saveLocals() { + int oldIp UNUSED = c.logicalIp; appendSaveLocals(&c); + assert(&c, oldIp == c.logicalIp); } virtual void checkBounds(ir::Value* object, diff --git a/src/codegen/compiler/context.cpp b/src/codegen/compiler/context.cpp index be316d0330..24436f1ed3 100644 --- a/src/codegen/compiler/context.cpp +++ b/src/codegen/compiler/context.cpp @@ -28,7 +28,6 @@ Context::Context(vm::System* system, Assembler* assembler, vm::Zone* zone, locals(0), saved(0), predecessor(0), - logicalCode(0), regFile(arch->registerFile()), regAlloc(system, arch->registerFile()), registerResources @@ -42,11 +41,9 @@ Context::Context(vm::System* system, Assembler* assembler, vm::Zone* zone, firstEvent(0), lastEvent(0), forkState(0), - subroutine(0), firstBlock(0), logicalIp(-1), constantCount(0), - logicalCodeLength(0), parameterFootprint(0), localFootprint(0), machineCodeSize(0), diff --git a/src/codegen/compiler/context.h b/src/codegen/compiler/context.h index 47404eefbc..9d03a96f35 100644 --- a/src/codegen/compiler/context.h +++ b/src/codegen/compiler/context.h @@ -35,7 +35,6 @@ class FrameResource; class ConstantPoolNode; class ForkState; -class MySubroutine; class Block; template @@ -50,6 +49,48 @@ List* reverseDestroy(List* cell) { return previous; } +class LogicalCode { + private: + util::Slice logicalCode; + + public: + LogicalCode() : logicalCode(0, 0) + { + } + + void init(vm::Zone* zone, size_t count) + { + // leave room for logical instruction -1 + size_t realCount = count + 1; + + logicalCode + = util::Slice::allocAndSet(zone, realCount, 0); + } + + void extend(vm::Zone* zone, size_t more) + { + util::Slice newCode + = logicalCode.cloneAndSet(zone, logicalCode.count + more, 0); + + for (size_t i = 0; i < logicalCode.count; i++) { + assert((vm::System*)0, logicalCode[i] == newCode[i]); + } + + logicalCode = newCode; + } + + size_t count() + { + return logicalCode.count - 1; + } + + LogicalInstruction*& operator[](int index) + { + // leave room for logical instruction -1 + return logicalCode[index + 1]; + } +}; + class Context { public: Context(vm::System* system, Assembler* assembler, vm::Zone* zone, @@ -64,7 +105,7 @@ class Context { Local* locals; List* saved; Event* predecessor; - LogicalInstruction** logicalCode; + LogicalCode logicalCode; const RegisterFile* regFile; RegisterAllocator regAlloc; RegisterResource* registerResources; @@ -76,11 +117,9 @@ class Context { Event* firstEvent; Event* lastEvent; ForkState* forkState; - MySubroutine* subroutine; Block* firstBlock; int logicalIp; unsigned constantCount; - unsigned logicalCodeLength; unsigned parameterFootprint; unsigned localFootprint; unsigned machineCodeSize; diff --git a/src/codegen/compiler/ir.cpp b/src/codegen/compiler/ir.cpp index aa2f09eb2f..abd6cc608f 100644 --- a/src/codegen/compiler/ir.cpp +++ b/src/codegen/compiler/ir.cpp @@ -15,14 +15,19 @@ namespace avian { namespace codegen { namespace compiler { -LogicalInstruction::LogicalInstruction(int index, Stack* stack, Local* locals): - firstEvent(0), lastEvent(0), immediatePredecessor(0), stack(stack), - locals(locals), machineOffset(0), subroutine(0), index(index) +LogicalInstruction::LogicalInstruction(int index, Stack* stack, Local* locals) + : firstEvent(0), + lastEvent(0), + immediatePredecessor(0), + stack(stack), + locals(locals), + machineOffset(0), + /*subroutine(0), */ index(index) { } LogicalInstruction* LogicalInstruction::next(Context* c) { LogicalInstruction* i = this; - for (unsigned n = i->index + 1; n < c->logicalCodeLength; ++n) { + for (size_t n = i->index + 1; n < c->logicalCode.count(); ++n) { i = c->logicalCode[n]; if (i) return i; } diff --git a/src/codegen/compiler/ir.h b/src/codegen/compiler/ir.h index 3bfdffc5d6..8b919c44a4 100644 --- a/src/codegen/compiler/ir.h +++ b/src/codegen/compiler/ir.h @@ -57,17 +57,9 @@ class LogicalInstruction { Stack* stack; Local* locals; Promise* machineOffset; - MySubroutine* subroutine; int index; }; -class MySubroutine: public Compiler::Subroutine { - public: - MySubroutine(): forkState(0) { } - - ForkState* forkState; -}; - class Block { public: Block(Event* head); diff --git a/src/compile.cpp b/src/compile.cpp index 03fb7e070c..3d78c68c24 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -759,110 +759,43 @@ class PoolElement: public avian::codegen::Promise { PoolElement* next; }; -class Context; -class SubroutineCall; - class Subroutine { public: - Subroutine(unsigned ip, unsigned logIndex, Subroutine* listNext, - Subroutine* stackNext): - listNext(listNext), - stackNext(stackNext), - calls(0), - handle(0), - ip(ip), - logIndex(logIndex), - stackIndex(0), - callCount(0), - tableIndex(0), - visited(false) + Subroutine(unsigned index, + unsigned returnAddress, + unsigned methodSize, + Subroutine* outer) + : index(index), + outer(outer), + returnAddress(returnAddress), + duplicatedBaseIp(methodSize * index), + visited(false) { } - Subroutine* listNext; - Subroutine* stackNext; - SubroutineCall* calls; - Compiler::Subroutine* handle; - unsigned ip; - unsigned logIndex; - unsigned stackIndex; - unsigned callCount; - unsigned tableIndex; + // Index of this subroutine, in the (unmaterialized) list of subroutines in + // this method. + // Note that in the presence of nested finalls, this could theoretically end + // up being greater than the number of jsr instructions (but this will be + // extremely rare - I don't think we've seen this in practice). + const unsigned index; + + // Subroutine outer to this one (if, for instance, we have nested finallys) + Subroutine* const outer; + + // How many levels deep of subroutines we're nested in. + // Note: This should always be len(outer), when treated as a list. + // const unsigned nesting; + + // Starting ip in the original bytecode (always < original bytecode size) + const unsigned returnAddress; + + // Starting ip for this subroutine's copy of the method bytecode + const unsigned duplicatedBaseIp; + bool visited; }; -class SubroutinePath; - -class SubroutineCall { - public: - SubroutineCall(Subroutine* subroutine, avian::codegen::Promise* returnAddress): - subroutine(subroutine), - returnAddress(returnAddress), - paths(0), - next(subroutine->calls) - { - subroutine->calls = this; - ++ subroutine->callCount; - } - - Subroutine* subroutine; - avian::codegen::Promise* returnAddress; - SubroutinePath* paths; - SubroutineCall* next; -}; - -class SubroutinePath { - public: - SubroutinePath(SubroutineCall* call, SubroutinePath* stackNext, - uintptr_t* rootTable): - call(call), - stackNext(stackNext), - listNext(call->paths), - rootTable(rootTable) - { - call->paths = this; - } - - SubroutineCall* call; - SubroutinePath* stackNext; - SubroutinePath* listNext; - uintptr_t* rootTable; -}; - -void -print(SubroutinePath* path) -{ - if (path) { - fprintf(stderr, " ("); - while (true) { - fprintf(stderr, "%p", path->call->returnAddress->resolved() ? - reinterpret_cast(path->call->returnAddress->value()) : 0); - path = path->stackNext; - if (path) { - fprintf(stderr, ", "); - } else { - break; - } - } - fprintf(stderr, ")"); - } -} - -class SubroutineTrace { - public: - SubroutineTrace(SubroutinePath* path, SubroutineTrace* next, - unsigned mapSize): - path(path), - next(next), - watch(false) - { - memset(map, 0, mapSize * BytesPerWord); - } - - SubroutinePath* path; - SubroutineTrace* next; - bool watch; - uintptr_t map[0]; -}; +class Context; class TraceElement: public avian::codegen::TraceHandler { public: @@ -875,10 +808,8 @@ class TraceElement: public avian::codegen::TraceHandler { context(context), address(0), next(next), - subroutineTrace(0), target(target), ip(ip), - subroutineTraceCount(0), argumentIndex(0), flags(flags), watch(false) @@ -896,10 +827,8 @@ class TraceElement: public avian::codegen::TraceHandler { Context* context; avian::codegen::Promise* address; TraceElement* next; - SubroutineTrace* subroutineTrace; object target; unsigned ip; - unsigned subroutineTraceCount; unsigned argumentIndex; unsigned flags; bool watch; @@ -931,8 +860,6 @@ enum Event { ClearEvent, PushExceptionHandlerEvent, TraceEvent, - PushSubroutineEvent, - PopSubroutineEvent }; unsigned @@ -947,26 +874,6 @@ frameMapSizeInWords(MyThread* t, object method) return ceilingDivide(frameMapSizeInBits(t, method), BitsPerWord); } -uint16_t* -makeVisitTable(MyThread* t, Zone* zone, object method) -{ - unsigned size = codeLength(t, methodCode(t, method)) * 2; - uint16_t* table = static_cast(zone->allocate(size)); - memset(table, 0, size); - return table; -} - -uintptr_t* -makeRootTable(MyThread* t, Zone* zone, object method) -{ - unsigned size = frameMapSizeInWords(t, method) - * codeLength(t, methodCode(t, method)) - * BytesPerWord; - uintptr_t* table = static_cast(zone->allocate(size)); - memset(table, 0xFF, size); - return table; -} - enum Thunk { #define THUNK(s) s##Thunk, @@ -1124,7 +1031,7 @@ class Context { assert(t, resultSize == 8); return local::getThunk(t, intToDoubleThunk); } - + default: abort(t); } } @@ -1233,11 +1140,17 @@ class Context { method(method), bootContext(bootContext), objectPool(0), - subroutines(0), + subroutineCount(0), traceLog(0), - visitTable(makeVisitTable(t, &zone, method)), - rootTable(makeRootTable(t, &zone, method)), - subroutineTable(0), + visitTable( + Slice::allocAndSet(&zone, + codeLength(t, methodCode(t, method)), + 0)), + rootTable( + Slice::allocAndSet(&zone, + codeLength(t, methodCode(t, method)) + * frameMapSizeInWords(t, method), + ~(uintptr_t)0)), executableAllocator(0), executableStart(0), executableSize(0), @@ -1262,11 +1175,10 @@ class Context { method(0), bootContext(0), objectPool(0), - subroutines(0), + subroutineCount(0), traceLog(0), - visitTable(0), - rootTable(0), - subroutineTable(0), + visitTable(0, 0), + rootTable(0, 0), executableAllocator(0), executableStart(0), executableSize(0), @@ -1304,6 +1216,16 @@ class Context { } } + void extendLogicalCode(unsigned more) + { + compiler->extendLogicalCode(more); + visitTable = visitTable.cloneAndSet(&zone, visitTable.count + more, 0); + rootTable = rootTable.cloneAndSet( + &zone, + rootTable.count + more * frameMapSizeInWords(thread, method), + ~(uintptr_t)0); + } + MyThread* thread; Zone zone; avian::codegen::Assembler* assembler; @@ -1312,11 +1234,10 @@ class Context { object method; BootContext* bootContext; PoolElement* objectPool; - Subroutine* subroutines; + unsigned subroutineCount; TraceElement* traceLog; - uint16_t* visitTable; - uintptr_t* rootTable; - Subroutine** subroutineTable; + Slice visitTable; + Slice rootTable; Allocator* executableAllocator; void* executableStart; unsigned executableSize; @@ -1750,29 +1671,43 @@ class Frame { : addressOperand(p); } - ir::Value* machineIp(unsigned logicalIp) + ir::Value* machineIpValue(unsigned logicalIp) { - return c->promiseConstant(c->machineIp(logicalIp), types.address); + return c->promiseConstant(machineIp(logicalIp), types.address); } - void visitLogicalIp(unsigned ip) { - c->visitLogicalIp(ip); - - context->eventLog.append(IpEvent); - context->eventLog.append2(ip); - } - - void startLogicalIp(unsigned ip) { - if (subroutine) { - context->subroutineTable[ip] = subroutine; + unsigned duplicatedIp(unsigned bytecodeIp) + { + if (UNLIKELY(subroutine)) { + return bytecodeIp + subroutine->duplicatedBaseIp; + } else { + return bytecodeIp; } + } - c->startLogicalIp(ip); + Promise* machineIp(unsigned bytecodeIp) + { + return c->machineIp(duplicatedIp(bytecodeIp)); + } + + void visitLogicalIp(unsigned bytecodeIp) + { + unsigned dupIp = duplicatedIp(bytecodeIp); + c->visitLogicalIp(dupIp); context->eventLog.append(IpEvent); - context->eventLog.append2(ip); + context->eventLog.append2(bytecodeIp); + } - this->ip = ip; + void startLogicalIp(unsigned bytecodeIp) + { + unsigned dupIp = duplicatedIp(bytecodeIp); + c->startLogicalIp(dupIp); + + context->eventLog.append(IpEvent); + context->eventLog.append2(bytecodeIp); + + this->ip = bytecodeIp; } void pushQuiet(ir::Type type, ir::Value* o) @@ -1817,25 +1752,22 @@ class Frame { pushSmall(o); } - void pushAddress(ir::Value* o) + void pushAddress() { - pushQuiet(types.i4, o); + c->pushed(ir::Type(ir::Type::Address, TargetBytesPerWord)); + pushedInt(); } void pushObject(ir::Value* o) { - assert(t, - o->type == types.object - || o->type.flavor() == ir::Type::Address - // TODO Temporary hack for Subroutine test!!! - || o->type.flavor() == ir::Type::Invalid); + assert(t, o->type == types.object || o->type.flavor() == ir::Type::Address); pushQuiet(types.object, o); pushedObject(); } void pushObject() { - c->pushed(); + c->pushed(types.object); pushedObject(); } @@ -2079,9 +2011,14 @@ class Frame { TraceElement* trace(object target, unsigned flags) { unsigned mapSize = frameMapSizeInWords(t, context->method); - TraceElement* e = context->traceLog = new - (context->zone.allocate(sizeof(TraceElement) + (mapSize * BytesPerWord))) - TraceElement(context, ip, target, flags, context->traceLog, mapSize); + TraceElement* e = context->traceLog = new ( + context->zone.allocate(sizeof(TraceElement) + (mapSize * BytesPerWord))) + TraceElement(context, + duplicatedIp(ip), + target, + flags, + context->traceLog, + mapSize); ++ context->traceLogCount; @@ -2169,80 +2106,52 @@ class Frame { } } - unsigned startSubroutine(unsigned ip, avian::codegen::Promise* returnAddress) { - pushAddress(absoluteAddressOperand(returnAddress)); + void startSubroutine(unsigned ip, unsigned returnAddress) + { + // TODO: in the future, push a value that we can track through type checking + pushAddress(); // push a dummy value to the stack, representing the return + // address (which we don't need, since we're expanding + // everything statically) - Subroutine* subroutine = 0; - for (Subroutine* s = context->subroutines; s; s = s->listNext) { - if (s->ip == ip) { - subroutine = s; - break; - } + if (DebugInstructions) { + fprintf(stderr, "startSubroutine %u %u\n", ip, returnAddress); } - if (subroutine == 0) { - context->subroutines = subroutine = new - (context->zone.allocate(sizeof(Subroutine))) - Subroutine(ip, context->eventLog.length() + 1 + BytesPerWord + 2, - context->subroutines, this->subroutine); + Subroutine* subroutine = new (&context->zone) + Subroutine(context->subroutineCount++, + returnAddress, + codeLength(t, methodCode(t, context->method)), + this->subroutine); - if (context->subroutineTable == 0) { - unsigned size = codeLength(t, methodCode(t, context->method)) - * sizeof(Subroutine*); + context->extendLogicalCode(codeLength(t, methodCode(t, context->method))); - context->subroutineTable = static_cast - (context->zone.allocate(size)); - - memset(context->subroutineTable, 0, size); - } - } - - subroutine->handle = c->startSubroutine(); this->subroutine = subroutine; - - SubroutineCall* call = new(&context->zone) - SubroutineCall(subroutine, returnAddress); - - context->eventLog.append(PushSubroutineEvent); - context->eventLog.appendAddress(call); - - unsigned nextIndexIndex = context->eventLog.length(); - context->eventLog.append2(0); - - c->saveLocals(); - - return nextIndexIndex; } - void returnFromSubroutine(unsigned returnAddressLocal) { - c->returnFromSubroutine( - subroutine->handle, - loadLocal(context, - 1, - ir::Type(ir::Type::Address, TargetBytesPerWord), - returnAddressLocal)); + unsigned endSubroutine(unsigned returnAddressLocal UNUSED) + { + // TODO: use returnAddressLocal to decide which subroutine we're returning + // from (in case it's ever not the most recent one entered). I'm unsure of + // whether such a subroutine pattern would pass bytecode verification. - subroutine->stackIndex = localOffsetFromStack - (t, translateLocalIndex(context, 1, returnAddressLocal), - context->method); + unsigned returnAddress = subroutine->returnAddress; + + if (DebugInstructions) { + fprintf(stderr, "endSubroutine %u %u\n", ip, returnAddress); + } + + subroutine = subroutine->outer; + + return returnAddress; } - void endSubroutine(unsigned nextIndexIndex) { - c->linkSubroutine(subroutine->handle); - - poppedInt(); - - context->eventLog.append(PopSubroutineEvent); - - context->eventLog.set2(nextIndexIndex, context->eventLog.length()); - - subroutine = subroutine->stackNext; - } - Context* context; MyThread* t; avian::codegen::Compiler* c; + + // Innermost subroutine we're compiling code for Subroutine* subroutine; + uint8_t* stackMap; unsigned ip; unsigned sp; @@ -3730,7 +3639,7 @@ bool integerBranch(MyThread* t, uint32_t newIp = (ip - 3) + offset; assert(t, newIp < codeLength(t, code)); - ir::Value* target = frame->machineIp(newIp); + ir::Value* target = frame->machineIpValue(newIp); switch (instruction) { case ifeq: @@ -3809,7 +3718,7 @@ bool floatBranch(MyThread* t, uint32_t newIp = (ip - 3) + offset; assert(t, newIp < codeLength(t, code)); - ir::Value* target = frame->machineIp(newIp); + ir::Value* target = frame->machineIpValue(newIp); switch (instruction) { case ifeq: @@ -4170,7 +4079,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, PROTECT(t, code); while (ip < codeLength(t, code)) { - if (context->visitTable[ip] ++) { + if (context->visitTable[frame->duplicatedIp(ip)]++) { // we've already visited this part of the code frame->visitLogicalIp(ip); goto next; @@ -4907,7 +4816,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - c->jmp(frame->machineIp(newIp)); + c->jmp(frame->machineIpValue(newIp)); ip = newIp; } break; @@ -4920,7 +4829,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - c->jmp(frame->machineIp(newIp)); + c->jmp(frame->machineIpValue(newIp)); ip = newIp; } break; @@ -5019,7 +4928,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = frame->popObject(); ir::Value* b = frame->popObject(); - ir::Value* target = frame->machineIp(newIp); + ir::Value* target = frame->machineIpValue(newIp); c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target); } goto branch; @@ -5040,7 +4949,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = frame->popInt(); ir::Value* b = frame->popInt(); - ir::Value* target = frame->machineIp(newIp); + ir::Value* target = frame->machineIpValue(newIp); c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target); } goto branch; @@ -5055,7 +4964,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, newIp = (ip - 3) + offset; assert(t, newIp < codeLength(t, code)); - ir::Value* target = frame->machineIp(newIp); + ir::Value* target = frame->machineIpValue(newIp); if(newIp <= ip) { compileSafePoint(t, c, frame); @@ -5079,7 +4988,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = c->constant(0, types.object); ir::Value* b = frame->popObject(); - ir::Value* target = frame->machineIp(newIp); + ir::Value* target = frame->machineIpValue(newIp); c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target); } goto branch; @@ -5432,15 +5341,12 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, assert(t, newIp < codeLength(t, code)); - unsigned start = frame->startSubroutine(newIp, c->machineIp(ip)); + frame->startSubroutine(newIp, ip); - c->jmp(frame->machineIp(newIp)); + c->jmp(frame->machineIpValue(newIp)); - stack.pushValue(start); - stack.pushValue(ip); - stack.pushValue(Unsubroutine); ip = newIp; - } goto start; + } break; case l2d: { frame->pushDouble(c->i2f(types.i8, types.f8, frame->popLong())); @@ -5630,7 +5536,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (pairCount) { ir::Value* default_ = frame->addressOperand( - frame->addressPromise(c->machineIp(defaultIp))); + frame->addressPromise(frame->machineIp(defaultIp))); avian::codegen::Promise* start = 0; uint32_t* ipTable = static_cast @@ -5647,8 +5553,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (i == 0) { start = p; } - c->poolAppendPromise - (frame->addressPromise(c->machineIp(newIp))); + c->poolAppendPromise(frame->addressPromise(frame->machineIp(newIp))); } assert(t, start); @@ -5678,7 +5583,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, goto switchloop; } else { // a switch statement with no cases, apparently - c->jmp(frame->machineIp(defaultIp)); + c->jmp(frame->machineIpValue(defaultIp)); ip = defaultIp; } } break; @@ -6146,8 +6051,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ret: { unsigned index = codeBody(t, code, ip); - frame->returnFromSubroutine(index); - } goto next; + + unsigned returnAddress = frame->endSubroutine(index); + c->jmp(frame->machineIpValue(returnAddress)); + ip = returnAddress; + } break; case return_: if (needsReturnBarrier(t, context->method)) { @@ -6189,8 +6097,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ipTable[i] = newIp; - avian::codegen::Promise* p = c->poolAppendPromise - (frame->addressPromise(c->machineIp(newIp))); + avian::codegen::Promise* p = c->poolAppendPromise( + frame->addressPromise(frame->machineIp(newIp))); if (i == 0) { start = p; } @@ -6203,7 +6111,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.i4, c->constant(bottom, types.i4), key, - frame->machineIp(defaultIp)); + frame->machineIpValue(defaultIp)); c->save(types.i4, key); @@ -6256,12 +6164,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ret: { unsigned index = codeReadInt16(t, code, ip); - c->jmp(loadLocal(context, - 1, - ir::Type(ir::Type::Address, TargetBytesPerWord), - index)); - frame->returnFromSubroutine(index); - } goto next; + + unsigned returnAddress = frame->endSubroutine(index); + c->jmp(frame->machineIpValue(returnAddress)); + ip = returnAddress; + } break; default: abort(t); } @@ -6281,12 +6188,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, return; case Unbranch: + if (DebugInstructions) { + fprintf(stderr, "Unbranch\n"); + } ip = stack.popValue(); c->restoreState(reinterpret_cast(stack.popValue())); frame = static_cast(stack.peek(sizeof(Frame))); goto loop; case Untable0: { + if (DebugInstructions) { + fprintf(stderr, "Untable0\n"); + } SwitchState* s = static_cast (stack.peek(sizeof(SwitchState))); @@ -6298,7 +6211,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, types.i4, c->constant(s->top, types.i4), s->key, - frame->machineIp(s->defaultIp)); + frame->machineIpValue(s->defaultIp)); c->save(types.i4, s->key); ip = s->defaultIp; @@ -6306,6 +6219,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto start; case Untable1: { + if (DebugInstructions) { + fprintf(stderr, "Untable1\n"); + } SwitchState* s = static_cast (stack.peek(sizeof(SwitchState))); @@ -6341,6 +6257,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto switchloop; case Unswitch: { + if (DebugInstructions) { + fprintf(stderr, "Unswitch\n"); + } SwitchState* s = static_cast (stack.peek(sizeof(SwitchState))); @@ -6351,6 +6270,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto switchloop; case Unsubroutine: { + if (DebugInstructions) { + fprintf(stderr, "Unsubroutine\n"); + } ip = stack.popValue(); unsigned start = stack.popValue(); frame = reinterpret_cast(stack.peek(sizeof(Frame))); @@ -6415,9 +6337,8 @@ int resolveIpBackwards(Context* context, int start, int end) { Thread* t = context->thread; - if (start >= static_cast - (codeLength(t, methodCode(t, context->method)))) - { + if (start >= static_cast(codeLength(t, methodCode(t, context->method)) + * (context->subroutineCount + 1))) { start = codeLength(t, methodCode(t, context->method)); } else { while (start >= end and context->visitTable[start] == 0) { @@ -6481,9 +6402,10 @@ truncateLineNumberTable(Thread* t, object table, unsigned length) return newTable; } -object -translateExceptionHandlerTable(MyThread* t, Context* context, intptr_t start, - intptr_t end) +object translateExceptionHandlerTable(MyThread* t, + Context* context, + intptr_t start, + intptr_t end) { avian::codegen::Compiler* c = context->compiler; @@ -6495,55 +6417,68 @@ translateExceptionHandlerTable(MyThread* t, Context* context, intptr_t start, unsigned length = exceptionHandlerTableLength(t, oldTable); - object newIndex = makeIntArray(t, length * 3); + object newIndex + = makeIntArray(t, length * (context->subroutineCount + 1) * 3); PROTECT(t, newIndex); - object newTable = makeArray(t, length + 1); + object newTable = makeArray(t, length * (context->subroutineCount + 1) + 1); PROTECT(t, newTable); unsigned ni = 0; - for (unsigned oi = 0; oi < length; ++ oi) { - uint64_t oldHandler = exceptionHandlerTableBody - (t, oldTable, oi); + for (unsigned subI = 0; subI <= context->subroutineCount; ++subI) { + unsigned duplicatedBaseIp + = subI * codeLength(t, methodCode(t, context->method)); - int handlerStart = resolveIpForwards - (context, exceptionHandlerStart(oldHandler), - exceptionHandlerEnd(oldHandler)); + for (unsigned oi = 0; oi < length; ++oi) { + uint64_t oldHandler = exceptionHandlerTableBody(t, oldTable, oi); - if (LIKELY(handlerStart >= 0)) { - assert(t, handlerStart < static_cast - (codeLength(t, methodCode(t, context->method)))); + int handlerStart = resolveIpForwards( + context, + duplicatedBaseIp + exceptionHandlerStart(oldHandler), + duplicatedBaseIp + exceptionHandlerEnd(oldHandler)); - int handlerEnd = resolveIpBackwards - (context, exceptionHandlerEnd(oldHandler), - exceptionHandlerStart(oldHandler)); + if (LIKELY(handlerStart >= 0)) { + assert( + t, + handlerStart + < static_cast(codeLength(t, methodCode(t, context->method)) + * (context->subroutineCount + 1))); - assert(t, handlerEnd >= 0); - assert(t, handlerEnd <= static_cast - (codeLength(t, methodCode(t, context->method)))); + int handlerEnd = resolveIpBackwards( + context, + duplicatedBaseIp + exceptionHandlerEnd(oldHandler), + duplicatedBaseIp + exceptionHandlerStart(oldHandler)); - intArrayBody(t, newIndex, ni * 3) - = c->machineIp(handlerStart)->value() - start; + assert(t, handlerEnd >= 0); + assert(t, + handlerEnd <= static_cast( + codeLength(t, methodCode(t, context->method)) + * (context->subroutineCount + 1))); - intArrayBody(t, newIndex, (ni * 3) + 1) - = (handlerEnd == static_cast - (codeLength(t, methodCode(t, context->method))) - ? end : c->machineIp(handlerEnd)->value()) - start; + intArrayBody(t, newIndex, ni* 3) = c->machineIp(handlerStart)->value() + - start; - intArrayBody(t, newIndex, (ni * 3) + 2) - = c->machineIp(exceptionHandlerIp(oldHandler))->value() - start; + intArrayBody(t, newIndex, (ni* 3) + 1) + = (handlerEnd == static_cast(codeLength( + t, methodCode(t, context->method))) + ? end + : c->machineIp(handlerEnd)->value()) - start; - object type; - if (exceptionHandlerCatchType(oldHandler)) { - type = resolveClassInPool - (t, context->method, exceptionHandlerCatchType(oldHandler) - 1); - } else { - type = 0; + intArrayBody(t, newIndex, (ni* 3) + 2) + = c->machineIp(exceptionHandlerIp(oldHandler))->value() - start; + + object type; + if (exceptionHandlerCatchType(oldHandler)) { + type = resolveClassInPool( + t, context->method, exceptionHandlerCatchType(oldHandler) - 1); + } else { + type = 0; + } + + set(t, newTable, ArrayBody + ((ni + 1) * BytesPerWord), type); + + ++ni; } - - set(t, newTable, ArrayBody + ((ni + 1) * BytesPerWord), type); - - ++ ni; } } @@ -6563,6 +6498,7 @@ translateExceptionHandlerTable(MyThread* t, Context* context, intptr_t start, object translateLineNumberTable(MyThread* t, Context* context, intptr_t start) { + // TODO: add line number table entries for subroutines (duplicated code) object oldTable = codeLineNumberTable(t, methodCode(t, context->method)); if (oldTable) { PROTECT(t, oldTable); @@ -6586,7 +6522,7 @@ translateLineNumberTable(MyThread* t, Context* context, intptr_t start) } if (UNLIKELY(ni < length)) { - newTable = truncateLineNumberTable(t, newTable, ni); + newTable = truncateLineNumberTable(t, newTable, ni); } return newTable; @@ -6609,37 +6545,24 @@ printSet(uintptr_t* m, unsigned limit) } } -void -calculateTryCatchRoots(Context* context, SubroutinePath* subroutinePath, - uintptr_t* roots, unsigned mapSize, unsigned start, - unsigned end) +void calculateTryCatchRoots( + Context* context, + uintptr_t* roots, + unsigned mapSize, + unsigned start, + unsigned end) { memset(roots, 0xFF, mapSize * BytesPerWord); if (DebugFrameMaps) { - fprintf(stderr, "calculate try/catch roots from %d to %d", start, end); - if (subroutinePath) { - fprintf(stderr, " "); - print(subroutinePath); - } - fprintf(stderr, "\n"); + fprintf(stderr, "calculate try/catch roots from %d to %d\n", start, end); } for (TraceElement* te = context->traceLog; te; te = te->next) { if (te->ip >= start and te->ip < end) { uintptr_t* traceRoots = 0; - if (subroutinePath == 0) { - traceRoots = te->map; - te->watch = true; - } else { - for (SubroutineTrace* t = te->subroutineTrace; t; t = t->next) { - if (t->path == subroutinePath) { - traceRoots = t->map; - t->watch = true; - break; - } - } - } + traceRoots = te->map; + te->watch = true; if (traceRoots) { if (DebugFrameMaps) { @@ -6666,10 +6589,11 @@ calculateTryCatchRoots(Context* context, SubroutinePath* subroutinePath, } } -unsigned -calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots, - unsigned eventIndex, SubroutinePath* subroutinePath = 0, - uintptr_t* resultRoots = 0) +unsigned calculateFrameMaps(MyThread* t, + Context* context, + uintptr_t* originalRoots, + unsigned eventIndex, + uintptr_t* resultRoots) { // for each instruction with more than one predecessor, and for each // stack position, determine if there exists a path to that @@ -6701,9 +6625,11 @@ calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots, Event e = static_cast(context->eventLog.get(eventIndex++)); switch (e) { case PushContextEvent: { - eventIndex = calculateFrameMaps - (t, context, RUNTIME_ARRAY_BODY(roots), eventIndex, subroutinePath, - resultRoots); + eventIndex = calculateFrameMaps(t, + context, + RUNTIME_ARRAY_BODY(roots), + eventIndex, /*subroutinePath,*/ + resultRoots); } break; case PopContextEvent: @@ -6719,9 +6645,8 @@ calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots, fprintf(stderr, "\n"); } - uintptr_t* tableRoots - = (subroutinePath ? subroutinePath->rootTable : context->rootTable) - + (ip * mapSize); + assert(context->thread, ip * mapSize <= context->rootTable.count); + uintptr_t* tableRoots = context->rootTable.begin() + (ip * mapSize); if (context->visitTable[ip] > 1) { for (unsigned wi = 0; wi < mapSize; ++wi) { @@ -6772,26 +6697,11 @@ calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots, unsigned end = context->eventLog.get2(eventIndex); eventIndex += 2; - if (context->subroutineTable and context->subroutineTable[start]) { - Subroutine* s = context->subroutineTable[start]; - unsigned originalEventIndex = eventIndex; + calculateTryCatchRoots( + context, RUNTIME_ARRAY_BODY(roots), mapSize, start, end); - for (SubroutineCall* c = s->calls; c; c = c->next) { - for (SubroutinePath* p = c->paths; p; p = p->listNext) { - calculateTryCatchRoots - (context, p, RUNTIME_ARRAY_BODY(roots), mapSize, start, end); - - eventIndex = calculateFrameMaps - (t, context, RUNTIME_ARRAY_BODY(roots), originalEventIndex, p); - } - } - } else { - calculateTryCatchRoots - (context, 0, RUNTIME_ARRAY_BODY(roots), mapSize, start, end); - - eventIndex = calculateFrameMaps - (t, context, RUNTIME_ARRAY_BODY(roots), eventIndex, 0); - } + eventIndex = calculateFrameMaps( + t, context, RUNTIME_ARRAY_BODY(roots), eventIndex, 0); } break; case TraceEvent: { @@ -6799,39 +6709,13 @@ calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots, if (DebugFrameMaps) { fprintf(stderr, " trace roots at ip %3d: ", ip); printSet(RUNTIME_ARRAY_BODY(roots), mapSize); - if (subroutinePath) { - fprintf(stderr, " "); - print(subroutinePath); - } fprintf(stderr, "\n"); } uintptr_t* map; bool watch; - if (subroutinePath == 0) { - map = te->map; - watch = te->watch; - } else { - SubroutineTrace* trace = 0; - for (SubroutineTrace* t = te->subroutineTrace; t; t = t->next) { - if (t->path == subroutinePath) { - trace = t; - break; - } - } - - if (trace == 0) { - te->subroutineTrace = trace = new - (context->zone.allocate - (sizeof(SubroutineTrace) + (mapSize * BytesPerWord))) - SubroutineTrace(subroutinePath, te->subroutineTrace, mapSize); - - ++ te->subroutineTraceCount; - } - - map = trace->map; - watch = trace->watch; - } + map = te->map; + watch = te->watch; for (unsigned wi = 0; wi < mapSize; ++wi) { uintptr_t v = RUNTIME_ARRAY_BODY(roots)[wi]; @@ -6850,45 +6734,6 @@ calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots, eventIndex += BytesPerWord; } break; - case PushSubroutineEvent: { - SubroutineCall* call; - context->eventLog.get(eventIndex, &call, BytesPerWord); - eventIndex += BytesPerWord; - - unsigned nextIndex = context->eventLog.get2(eventIndex); - - eventIndex = nextIndex; - - SubroutinePath* path = 0; - for (SubroutinePath* p = call->paths; p; p = p->listNext) { - if (p->stackNext == subroutinePath) { - path = p; - break; - } - } - - if (path == 0) { - path = new(&context->zone) - SubroutinePath(call, subroutinePath, - makeRootTable(t, &(context->zone), context->method)); - } - - THREAD_RUNTIME_ARRAY(t, uintptr_t, subroutineRoots, mapSize); - - calculateFrameMaps - (t, context, RUNTIME_ARRAY_BODY(roots), call->subroutine->logIndex, - path, RUNTIME_ARRAY_BODY(subroutineRoots)); - - for (unsigned wi = 0; wi < mapSize; ++wi) { - RUNTIME_ARRAY_BODY(roots)[wi] - &= RUNTIME_ARRAY_BODY(subroutineRoots)[wi]; - } - } break; - - case PopSubroutineEvent: - eventIndex = static_cast(-1); - goto exit; - default: abort(t); } } @@ -6898,10 +6743,6 @@ calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots, if (DebugFrameMaps) { fprintf(stderr, "result roots at ip %3d: ", ip); printSet(RUNTIME_ARRAY_BODY(roots), mapSize); - if (subroutinePath) { - fprintf(stderr, " "); - print(subroutinePath); - } fprintf(stderr, "\n"); } @@ -6959,15 +6800,16 @@ clearBit(int32_t* dst, unsigned index) dst[index / 32] &= ~(static_cast(1) << (index % 32)); } -void -copyFrameMap(int32_t* dst, uintptr_t* src, unsigned mapSizeInBits, - unsigned offset, TraceElement* p, - SubroutinePath* subroutinePath) +void copyFrameMap(int32_t* dst, + uintptr_t* src, + unsigned mapSizeInBits, + unsigned offset, + TraceElement* p /*, + SubroutinePath* subroutinePath*/) { if (DebugFrameMaps) { fprintf(stderr, " orig roots at ip %3d: ", p->ip); printSet(src, ceilingDivide(mapSizeInBits, BitsPerWord)); - print(subroutinePath); fprintf(stderr, "\n"); fprintf(stderr, " final roots at ip %3d: ", p->ip); @@ -6988,7 +6830,6 @@ copyFrameMap(int32_t* dst, uintptr_t* src, unsigned mapSizeInBits, } if (DebugFrameMaps) { - print(subroutinePath); fprintf(stderr, "\n"); } } @@ -7029,157 +6870,6 @@ class FrameMapTablePath { int32_t elements[0]; }; -int -compareInt32s(const void* va, const void* vb) -{ - return *static_cast(va) - *static_cast(vb); -} - -int -compare(SubroutinePath* a, SubroutinePath* b) -{ - if (a->stackNext) { - int d = compare(a->stackNext, b->stackNext); - if (d) return d; - } - int64_t av = a->call->returnAddress->value(); - int64_t bv = b->call->returnAddress->value(); - if (av > bv) { - return 1; - } else if (av < bv) { - return -1; - } else { - return 0; - } -} - -int -compareSubroutineTracePointers(const void* va, const void* vb) -{ - return compare((*static_cast(va))->path, - (*static_cast(vb))->path); -} - -object -makeGeneralFrameMapTable(MyThread* t, Context* context, uint8_t* start, - TraceElement** elements, unsigned elementCount, - unsigned pathFootprint, unsigned mapCount) -{ - unsigned mapSize = frameMapSizeInBits(t, context->method); - unsigned indexOffset = sizeof(FrameMapTableHeader); - unsigned mapsOffset = indexOffset - + (elementCount * sizeof(FrameMapTableIndexElement)); - unsigned pathsOffset = mapsOffset + (ceilingDivide(mapCount * mapSize, 32) * 4); - - object table = makeByteArray(t, pathsOffset + pathFootprint); - - int8_t* body = &byteArrayBody(t, table, 0); - new (body) FrameMapTableHeader(elementCount); - - unsigned nextTableIndex = pathsOffset; - unsigned nextMapIndex = 0; - for (unsigned i = 0; i < elementCount; ++i) { - TraceElement* p = elements[i]; - unsigned mapBase = nextMapIndex; - - unsigned pathIndex; - if (p->subroutineTrace) { - FrameMapTablePath* previous = 0; - Subroutine* subroutine = p->subroutineTrace->path->call->subroutine; - for (Subroutine* s = subroutine; s; s = s->stackNext) { - if (s->tableIndex == 0) { - unsigned pathObjectSize = sizeof(FrameMapTablePath) - + (sizeof(int32_t) * s->callCount); - - assert(t, nextTableIndex + pathObjectSize - <= byteArrayLength(t, table)); - - s->tableIndex = nextTableIndex; - - nextTableIndex += pathObjectSize; - - FrameMapTablePath* current = new (body + s->tableIndex) - FrameMapTablePath - (s->stackIndex, s->callCount, - s->stackNext ? s->stackNext->tableIndex : 0); - - unsigned i = 0; - for (SubroutineCall* c = subroutine->calls; c; c = c->next) { - assert(t, i < s->callCount); - - current->elements[i++] - = static_cast(c->returnAddress->value()) - - reinterpret_cast(start); - } - assert(t, i == s->callCount); - - qsort(current->elements, s->callCount, sizeof(int32_t), - compareInt32s); - - if (previous) { - previous->next = s->tableIndex; - } - - previous = current; - } else { - break; - } - } - - pathIndex = subroutine->tableIndex; - - THREAD_RUNTIME_ARRAY - (t, SubroutineTrace*, traces, p->subroutineTraceCount); - - unsigned i = 0; - for (SubroutineTrace* trace = p->subroutineTrace; - trace; trace = trace->next) - { - assert(t, i < p->subroutineTraceCount); - RUNTIME_ARRAY_BODY(traces)[i++] = trace; - } - assert(t, i == p->subroutineTraceCount); - - qsort(RUNTIME_ARRAY_BODY(traces), p->subroutineTraceCount, - sizeof(SubroutineTrace*), compareSubroutineTracePointers); - - for (unsigned i = 0; i < p->subroutineTraceCount; ++i) { - assert(t, mapsOffset + ceilingDivide(nextMapIndex + mapSize, 32) * 4 - <= pathsOffset); - - copyFrameMap(reinterpret_cast(body + mapsOffset), - RUNTIME_ARRAY_BODY(traces)[i]->map, mapSize, - nextMapIndex, p, RUNTIME_ARRAY_BODY(traces)[i]->path); - - nextMapIndex += mapSize; - } - } else { - pathIndex = 0; - - assert(t, mapsOffset + ceilingDivide(nextMapIndex + mapSize, 32) * 4 - <= pathsOffset); - - copyFrameMap(reinterpret_cast(body + mapsOffset), p->map, - mapSize, nextMapIndex, p, 0); - - nextMapIndex += mapSize; - } - - unsigned elementIndex = indexOffset - + (i * sizeof(FrameMapTableIndexElement)); - - assert(t, elementIndex + sizeof(FrameMapTableIndexElement) <= mapsOffset); - - new (body + elementIndex) FrameMapTableIndexElement - (static_cast(p->address->value()) - - reinterpret_cast(start), mapBase, pathIndex); - } - - assert(t, nextMapIndex == mapCount * mapSize); - - return table; -} - object makeSimpleFrameMapTable(MyThread* t, Context* context, uint8_t* start, TraceElement** elements, unsigned elementCount) @@ -7201,8 +6891,11 @@ makeSimpleFrameMapTable(MyThread* t, Context* context, uint8_t* start, <= intArrayLength(t, table)); if (mapSize) { - copyFrameMap(&intArrayBody(t, table, elementCount), p->map, - mapSize, i * mapSize, p, 0); + copyFrameMap(&intArrayBody(t, table, elementCount), + p->map, + mapSize, + i * mapSize, + p); } } @@ -7321,29 +7014,12 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) if (context->traceLogCount) { THREAD_RUNTIME_ARRAY(t, TraceElement*, elements, context->traceLogCount); unsigned index = 0; - unsigned pathFootprint = 0; - unsigned mapCount = 0; + // unsigned pathFootprint = 0; + // unsigned mapCount = 0; for (TraceElement* p = context->traceLog; p; p = p->next) { assert(t, index < context->traceLogCount); if (p->address) { - SubroutineTrace* trace = p->subroutineTrace; - unsigned myMapCount = 1; - if (trace) { - for (Subroutine* s = trace->path->call->subroutine; - s; s = s->stackNext) - { - unsigned callCount = s->callCount; - myMapCount *= callCount; - if (not s->visited) { - s->visited = true; - pathFootprint += sizeof(FrameMapTablePath) - + (sizeof(int32_t) * callCount); - } - } - } - - mapCount += myMapCount; RUNTIME_ARRAY_BODY(elements)[index++] = p; @@ -7359,14 +7035,15 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) sizeof(TraceElement*), compareTraceElementPointers); object map; - if (pathFootprint) { - map = makeGeneralFrameMapTable - (t, context, start, RUNTIME_ARRAY_BODY(elements), index, pathFootprint, - mapCount); - } else { + // if (pathFootprint) { + // map = makeGeneralFrameMapTable + // (t, context, start, RUNTIME_ARRAY_BODY(elements), index, + // pathFootprint, + // mapCount); + // } else { map = makeSimpleFrameMapTable (t, context, start, RUNTIME_ARRAY_BODY(elements), index); - } + // } set(t, methodCode(t, context->method), CodePool, map); } @@ -7466,7 +7143,7 @@ compile(MyThread* t, Context* context) compile(t, &frame, 0); context->dirtyRoots = false; - unsigned eventIndex = calculateFrameMaps(t, context, 0, 0); + unsigned eventIndex = calculateFrameMaps(t, context, 0, 0, 0); object eht = codeExceptionHandlerTable(t, methodCode(t, context->method)); if (eht) { @@ -7481,48 +7158,53 @@ compile(MyThread* t, Context* context) while (progress) { progress = false; - for (unsigned i = 0; i < exceptionHandlerTableLength(t, eht); ++i) { - uint64_t eh = exceptionHandlerTableBody(t, eht, i); - int start = resolveIpForwards - (context, exceptionHandlerStart(eh), exceptionHandlerEnd(eh)); + for (unsigned subI = 0; subI <= context->subroutineCount; ++subI) { + unsigned duplicatedBaseIp + = subI * codeLength(t, methodCode(t, context->method)); - if ((not RUNTIME_ARRAY_BODY(visited)[i]) - and start >= 0 - and context->visitTable[start]) - { - RUNTIME_ARRAY_BODY(visited)[i] = true; - progress = true; + for (unsigned i = 0; i < exceptionHandlerTableLength(t, eht); ++i) { + uint64_t eh = exceptionHandlerTableBody(t, eht, i); + int start + = resolveIpForwards(context, + duplicatedBaseIp + exceptionHandlerStart(eh), + duplicatedBaseIp + exceptionHandlerEnd(eh)); - c->restoreState(state); + if ((not RUNTIME_ARRAY_BODY(visited)[i])and start + >= 0 and context->visitTable[start]) { + RUNTIME_ARRAY_BODY(visited)[i] = true; + progress = true; - THREAD_RUNTIME_ARRAY - (t, uint8_t, stackMap, - codeMaxStack(t, methodCode(t, context->method))); - Frame frame2(&frame, RUNTIME_ARRAY_BODY(stackMap)); + c->restoreState(state); - unsigned end = exceptionHandlerEnd(eh); - if (exceptionHandlerIp(eh) >= static_cast(start) - and exceptionHandlerIp(eh) < end) - { - end = exceptionHandlerIp(eh); + THREAD_RUNTIME_ARRAY( + t, + uint8_t, + stackMap, + codeMaxStack(t, methodCode(t, context->method))); + Frame frame2(&frame, RUNTIME_ARRAY_BODY(stackMap)); + + unsigned end = duplicatedBaseIp + exceptionHandlerEnd(eh); + if (exceptionHandlerIp(eh) >= static_cast(start) + and exceptionHandlerIp(eh) < end) { + end = duplicatedBaseIp + exceptionHandlerIp(eh); + } + + context->eventLog.append(PushExceptionHandlerEvent); + context->eventLog.append2(start); + context->eventLog.append2(end); + + for (unsigned i = 1; + i < codeMaxStack(t, methodCode(t, context->method)); + ++i) { + frame2.set(localSize(t, context->method) + i, Frame::Integer); + } + + compile(t, &frame2, exceptionHandlerIp(eh), start); + + context->eventLog.append(PopContextEvent); + + eventIndex = calculateFrameMaps(t, context, 0, eventIndex, 0); } - - context->eventLog.append(PushExceptionHandlerEvent); - context->eventLog.append2(start); - context->eventLog.append2(end); - - for (unsigned i = 1; - i < codeMaxStack(t, methodCode(t, context->method)); - ++i) - { - frame2.set(localSize(t, context->method) + i, Frame::Integer); - } - - compile(t, &frame2, exceptionHandlerIp(eh), start); - - context->eventLog.append(PopContextEvent); - - eventIndex = calculateFrameMaps(t, context, 0, eventIndex); } } } @@ -7530,7 +7212,7 @@ compile(MyThread* t, Context* context) while (context->dirtyRoots) { context->dirtyRoots = false; - calculateFrameMaps(t, context, 0, 0); + calculateFrameMaps(t, context, 0, 0, 0); } } From 746c0fa0e8490a6b2f37ee7213dafa5ae46238c7 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 18:42:40 -0600 Subject: [PATCH 54/89] remove ir::Type::Invalid, no longer needed for Subroutine --- include/avian/codegen/ir.h | 4 ---- src/codegen/compiler.cpp | 8 +------- src/compile.cpp | 12 ++---------- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h index a1e4d38001..54ac8e0982 100644 --- a/include/avian/codegen/ir.h +++ b/include/avian/codegen/ir.h @@ -34,10 +34,6 @@ class Type { // Represents the lack of a return value // TODO: remove when possible Void, - - // Represents some arbitrary type that should not be accessed - // TODO: remove when possible - Invalid }; private: diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index d1dafc2a0e..45bf92ccc1 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -1224,7 +1224,6 @@ unsigned typeFootprint(Context* c, ir::Type type) case ir::Type::Object: case ir::Type::Address: case ir::Type::Half: - case ir::Type::Invalid: return 1; case ir::Type::Void: return 0; @@ -2465,12 +2464,7 @@ class MyCompiler: public Compiler { virtual void return_(ir::Type type, ir::Value* a) { - // TODO: once type information is flowed properly, enable this assert. - // Some time later, we can remove the parameter. - assert(&c, - a->type == type - // TODO Temporary hack for Subroutine test!!! - || a->type.flavor() == ir::Type::Invalid); + assert(&c, a->type == type); appendReturn(&c, type.size(), static_cast(a)); } diff --git a/src/compile.cpp b/src/compile.cpp index 3d78c68c24..be33212a80 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1278,7 +1278,6 @@ ir::Value* loadLocal(Context* context, && (result->type.flavor() == ir::Type::Object || result->type.flavor() == ir::Type::Address)) // TODO Temporary hack for Subroutine test!!! - || result->type.flavor() == ir::Type::Invalid || result->type.flavor() == ir::Type::Integer); return result; } @@ -1295,7 +1294,6 @@ void storeLocal(Context* context, && (value->type.flavor() == ir::Type::Object || value->type.flavor() == ir::Type::Address)) // TODO Temporary hack for Subroutine test!!! - || value->type.flavor() == ir::Type::Invalid || value->type.flavor() == ir::Type::Integer); context->compiler->storeLocal (footprint, value, translateLocalIndex(context, footprint, index)); @@ -1739,10 +1737,7 @@ class Frame { void pushInt(ir::Value* o) { - assert(t, - o->type == types.i4 - // TODO Temporary hack for Subroutine test!!! - || o->type.flavor() == ir::Type::Invalid); + assert(t, o->type == types.i4); pushSmall(o); } @@ -1780,10 +1775,7 @@ class Frame { void pushLong(ir::Value* o) { - assert(t, - o->type == types.i8 - // TODO Temporary hack for Subroutine test!!! - || o->type.flavor() == ir::Type::Invalid); + assert(t, o->type == types.i8); pushLarge(o); } From 6fdd5d13cae46b1ea2e56922a76e321097a48519 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 19:46:15 -0600 Subject: [PATCH 55/89] remove redundant return_ type parameter --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 5 ++--- src/compile.cpp | 11 +++++------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index d4290cbe63..c200fdb37f 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -90,7 +90,7 @@ class Compiler { ir::Type resultType, util::Slice arguments) = 0; - virtual void return_(ir::Type type, ir::Value* value) = 0; + virtual void return_(ir::Value* value) = 0; virtual void return_() = 0; virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 45bf92ccc1..be62ca5904 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2462,10 +2462,9 @@ class MyCompiler: public Compiler { return result; } - virtual void return_(ir::Type type, ir::Value* a) + virtual void return_(ir::Value* a) { - assert(&c, a->type == type); - appendReturn(&c, type.size(), static_cast(a)); + appendReturn(&c, a->type.size(), static_cast(a)); } virtual void return_() diff --git a/src/compile.cpp b/src/compile.cpp index be33212a80..4ff08d7168 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1715,7 +1715,6 @@ class Frame { void pushLongQuiet(ir::Value* o) { - // assert(t, o->type == types.i8); pushQuiet(types.i8, o); } @@ -4358,7 +4357,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case areturn: { handleExit(t, frame); - c->return_(types.object, frame->popObject()); + c->return_(frame->popObject()); } goto next; case arraylength: { @@ -5273,13 +5272,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ireturn: { handleExit(t, frame); - c->return_(types.i4, frame->popInt()); + c->return_(frame->popInt()); } goto next; case freturn: { handleExit(t, frame); - c->return_(types.f4, frame->popInt()); + c->return_(frame->popInt()); } goto next; case istore: @@ -5594,13 +5593,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lreturn: { handleExit(t, frame); - c->return_(types.i8, frame->popLong()); + c->return_(frame->popLong()); } goto next; case dreturn: { handleExit(t, frame); - c->return_(types.f8, frame->popLong()); + c->return_(frame->popLong()); } goto next; case lshl: From 69966f1d36c6ad0bef6defb3911adf6f235594bd Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 19:49:56 -0600 Subject: [PATCH 56/89] add type assert in load, fix ensuing problems --- src/codegen/compiler.cpp | 1 + src/compile.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index be62ca5904..156b79625b 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2613,6 +2613,7 @@ class MyCompiler: public Compiler { { assert(&c, srcType.flavor() == dstType.flavor()); assert(&c, src->type.flavor() == dstType.flavor()); + assert(&c, src->type == srcType); Value* dst = value(&c, dstType); appendMove(&c, diff --git a/src/compile.cpp b/src/compile.cpp index 4ff08d7168..6cd2fe1878 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4361,11 +4361,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto next; case arraylength: { - frame->pushInt( - c->load(ir::SignExtend, - types.address, - c->memory(frame->popObject(), types.i4, TargetArrayLength), - types.i4)); + frame->pushInt(c->load( + ir::SignExtend, + types.address, + c->memory(frame->popObject(), types.address, TargetArrayLength), + types.i4)); } break; case astore: @@ -4679,7 +4679,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( ir::SignExtend, types.i1, - c->memory(table, types.i4, targetFieldOffset(context, field)), + c->memory(table, types.i1, targetFieldOffset(context, field)), types.i4)); break; @@ -4687,7 +4687,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( ir::ZeroExtend, types.i2, - c->memory(table, types.i4, targetFieldOffset(context, field)), + c->memory(table, types.i2, targetFieldOffset(context, field)), types.i4)); break; @@ -4695,7 +4695,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt(c->load( ir::SignExtend, types.i2, - c->memory(table, types.i4, targetFieldOffset(context, field)), + c->memory(table, types.i2, targetFieldOffset(context, field)), types.i4)); break; From 963b371e04f20afac1c54bbb8a91d7792f82d2b8 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 19:53:33 -0600 Subject: [PATCH 57/89] remove redundant load srcType parameter --- include/avian/codegen/compiler.h | 1 - src/codegen/compiler.cpp | 7 ++----- src/compile.cpp | 28 ++++------------------------ 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index c200fdb37f..1dfa289ba8 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -115,7 +115,6 @@ class Compiler { virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) = 0; virtual ir::Value* load(ir::SignExtendMode signExtend, - ir::Type srcType, ir::Value* src, ir::Type dstType) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 156b79625b..cb46eb22b7 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2607,19 +2607,16 @@ class MyCompiler: public Compiler { } virtual ir::Value* load(ir::SignExtendMode signExtend, - ir::Type srcType, ir::Value* src, ir::Type dstType) { - assert(&c, srcType.flavor() == dstType.flavor()); assert(&c, src->type.flavor() == dstType.flavor()); - assert(&c, src->type == srcType); Value* dst = value(&c, dstType); appendMove(&c, signExtend == ir::SignExtend ? lir::Move : lir::MoveZ, - srcType.size(), - srcType.size(), + src->type.size(), + src->type.size(), static_cast(src), dstType.size() < TargetBytesPerWord ? TargetBytesPerWord : dstType.size(), diff --git a/src/compile.cpp b/src/compile.cpp index 6cd2fe1878..3868badc02 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3739,7 +3739,6 @@ ir::Value* popLongAddress(Frame* frame) ir::Types types(TargetBytesPerWord); return TargetBytesPerWord == 8 ? frame->popLong() : frame->c->load(ir::SignExtend, - types.i8, frame->popLong(), types.address); } @@ -3783,7 +3782,7 @@ intrinsic(MyThread* t, Frame* frame, object target) ir::Value* address = popLongAddress(frame); frame->popObject(); frame->pushInt(c->load( - ir::SignExtend, types.i1, c->memory(address, types.i1), types.i4)); + ir::SignExtend, c->memory(address, types.i1), types.i4)); return true; } else if (MATCH(methodName(t, target), "putByte") and MATCH(methodSpec(t, target), "(JB)V")) @@ -3801,7 +3800,7 @@ intrinsic(MyThread* t, Frame* frame, object target) ir::Value* address = popLongAddress(frame); frame->popObject(); frame->pushInt(c->load( - ir::SignExtend, types.i2, c->memory(address, types.i2), types.i4)); + ir::SignExtend, c->memory(address, types.i2), types.i4)); return true; } else if ((MATCH(methodName(t, target), "putShort") and MATCH(methodSpec(t, target), "(JS)V")) @@ -3823,7 +3822,7 @@ intrinsic(MyThread* t, Frame* frame, object target) ir::Type type = MATCH(methodName(t, target), "getInt") ? types.i4 : types.f4; frame->pushSmall( - c->load(ir::SignExtend, type, c->memory(address, type), type)); + c->load(ir::SignExtend, c->memory(address, type), type)); return true; } else if ((MATCH(methodName(t, target), "putInt") and MATCH(methodSpec(t, target), "(JI)V")) @@ -3847,7 +3846,7 @@ intrinsic(MyThread* t, Frame* frame, object target) ir::Type type = MATCH(methodName(t, target), "getLong") ? types.i8 : types.f8; frame->pushLarge( - c->load(ir::SignExtend, type, c->memory(address, type), type)); + c->load(ir::SignExtend, c->memory(address, type), type)); return true; } else if ((MATCH(methodName(t, target), "putLong") and MATCH(methodSpec(t, target), "(JJ)V")) @@ -3867,7 +3866,6 @@ intrinsic(MyThread* t, Frame* frame, object target) ir::Value* address = popLongAddress(frame); frame->popObject(); frame->pushLong(c->load(ir::SignExtend, - types.address, c->memory(address, types.address), types.i8)); return true; @@ -4148,7 +4146,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case aaload: frame->pushObject( c->load(ir::SignExtend, - types.object, c->memory(array, types.object, TargetArrayBody, index), types.object)); break; @@ -4156,7 +4153,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case faload: frame->pushFloat( c->load(ir::SignExtend, - types.f4, c->memory(array, types.f4, TargetArrayBody, index), types.f4)); break; @@ -4164,7 +4160,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case iaload: frame->pushInt( c->load(ir::SignExtend, - types.i4, c->memory(array, types.i4, TargetArrayBody, index), types.i4)); break; @@ -4172,7 +4167,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case baload: frame->pushInt( c->load(ir::SignExtend, - types.i1, c->memory(array, types.i1, TargetArrayBody, index), types.i4)); break; @@ -4180,7 +4174,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case caload: frame->pushInt( c->load(ir::ZeroExtend, - types.i2, c->memory(array, types.i2, TargetArrayBody, index), types.i4)); break; @@ -4188,7 +4181,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case daload: frame->pushDouble( c->load(ir::SignExtend, - types.f8, c->memory(array, types.f8, TargetArrayBody, index), types.f8)); break; @@ -4196,7 +4188,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case laload: frame->pushLong( c->load(ir::SignExtend, - types.i8, c->memory(array, types.i8, TargetArrayBody, index), types.i8)); break; @@ -4204,7 +4195,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case saload: frame->pushInt( c->load(ir::SignExtend, - types.i2, c->memory(array, types.i2, TargetArrayBody, index), types.i4)); break; @@ -4363,7 +4353,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case arraylength: { frame->pushInt(c->load( ir::SignExtend, - types.address, c->memory(frame->popObject(), types.address, TargetArrayLength), types.i4)); } break; @@ -4678,7 +4667,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case BooleanField: frame->pushInt(c->load( ir::SignExtend, - types.i1, c->memory(table, types.i1, targetFieldOffset(context, field)), types.i4)); break; @@ -4686,7 +4674,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case CharField: frame->pushInt(c->load( ir::ZeroExtend, - types.i2, c->memory(table, types.i2, targetFieldOffset(context, field)), types.i4)); break; @@ -4694,7 +4681,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ShortField: frame->pushInt(c->load( ir::SignExtend, - types.i2, c->memory(table, types.i2, targetFieldOffset(context, field)), types.i4)); break; @@ -4702,7 +4688,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case FloatField: frame->pushFloat(c->load( ir::SignExtend, - types.f4, c->memory(table, types.f4, targetFieldOffset(context, field)), types.f4)); break; @@ -4710,7 +4695,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case IntField: frame->pushInt(c->load( ir::SignExtend, - types.i4, c->memory(table, types.i4, targetFieldOffset(context, field)), types.i4)); break; @@ -4718,7 +4702,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case DoubleField: frame->pushDouble(c->load( ir::SignExtend, - types.f8, c->memory(table, types.f8, targetFieldOffset(context, field)), types.f8)); break; @@ -4726,7 +4709,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case LongField: frame->pushLong(c->load( ir::SignExtend, - types.i8, c->memory(table, types.i8, targetFieldOffset(context, field)), types.i8)); break; @@ -4734,7 +4716,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ObjectField: frame->pushObject(c->load( ir::SignExtend, - types.object, c->memory(table, types.object, targetFieldOffset(context, field)), types.object)); break; @@ -6233,7 +6214,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, normalizedKey); c->jmp(c->load(ir::SignExtend, - types.address, context->bootContext ? c->binaryOp(lir::Add, types.address, From c843a97e23f91d50290954493cc799a63d61dc80 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 19:56:21 -0600 Subject: [PATCH 58/89] remove redundant f2f aType parameter --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 7 +++---- src/compile.cpp | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 1dfa289ba8..36f89690b4 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -136,7 +136,7 @@ class Compiler { ir::Value* a) = 0; virtual void nullaryOp(lir::Operation op) = 0; - virtual ir::Value* f2f(ir::Type aType, ir::Type resType, ir::Value* a) = 0; + virtual ir::Value* f2f(ir::Type resType, ir::Value* a) = 0; virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a) = 0; virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index cb46eb22b7..55308e24d3 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2692,16 +2692,15 @@ class MyCompiler: public Compiler { return result; } - virtual ir::Value* f2f(ir::Type aType, ir::Type resType, ir::Value* a) + virtual ir::Value* f2f(ir::Type resType, ir::Value* a) { - assert(&c, aType == a->type); assert(&c, isFloatValue(a)); assert(&c, resType.flavor() == ir::Type::Float); - assert(&c, aType.flavor() == ir::Type::Float); + assert(&c, a->type.flavor() == ir::Type::Float); Value* result = value(&c, resType); appendTranslate(&c, lir::Float2Float, - aType.size(), + a->type.size(), static_cast(a), resType.size(), result); diff --git a/src/compile.cpp b/src/compile.cpp index 3868badc02..4e50fad7dc 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4428,7 +4428,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case d2f: { - frame->pushFloat(c->f2f(types.f8, types.f4, frame->popLong())); + frame->pushFloat(c->f2f(types.f4, frame->popLong())); } break; case d2i: { @@ -4529,7 +4529,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case f2d: { - frame->pushDouble(c->f2f(types.f4, types.f8, frame->popInt())); + frame->pushDouble(c->f2f(types.f8, frame->popInt())); } break; case f2i: { From c9313d580254d73c3d12da671a305940ac74af9f Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 19:58:00 -0600 Subject: [PATCH 59/89] add type assert in f2i & i2f --- src/codegen/compiler.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 55308e24d3..05a99bb49c 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2709,8 +2709,7 @@ class MyCompiler: public Compiler { virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a) { - // TODO: enable when possible - // assert(&c, aType == a->type); + assert(&c, aType == a->type); assert(&c, isFloatValue(a)); assert(&c, resType.flavor() != ir::Type::Float); assert(&c, aType.flavor() == ir::Type::Float); @@ -2726,8 +2725,7 @@ class MyCompiler: public Compiler { virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a) { - // TODO: enable when possible - // assert(&c, aType == a->type); + assert(&c, aType == a->type); assert(&c, isGeneralValue(a)); assert(&c, resType.flavor() == ir::Type::Float); assert(&c, aType.flavor() != ir::Type::Float); From b853f1a5946022fbd467fc3bc31e4b85f8fd190a Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 20:00:10 -0600 Subject: [PATCH 60/89] remove redundant f2i & i2f aType parameter --- include/avian/codegen/compiler.h | 4 ++-- src/codegen/compiler.cpp | 13 ++++--------- src/compile.cpp | 16 ++++++++-------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 36f89690b4..fb34919a03 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -137,8 +137,8 @@ class Compiler { virtual void nullaryOp(lir::Operation op) = 0; virtual ir::Value* f2f(ir::Type resType, ir::Value* a) = 0; - virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a) = 0; - virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a) = 0; + virtual ir::Value* f2i(ir::Type resType, ir::Value* a) = 0; + virtual ir::Value* i2f(ir::Type resType, ir::Value* a) = 0; virtual void compile(uintptr_t stackOverflowHandler, unsigned stackLimitOffset) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 05a99bb49c..1a17e9f9cd 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2696,7 +2696,6 @@ class MyCompiler: public Compiler { { assert(&c, isFloatValue(a)); assert(&c, resType.flavor() == ir::Type::Float); - assert(&c, a->type.flavor() == ir::Type::Float); Value* result = value(&c, resType); appendTranslate(&c, lir::Float2Float, @@ -2707,32 +2706,28 @@ class MyCompiler: public Compiler { return result; } - virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a) + virtual ir::Value* f2i(ir::Type resType, ir::Value* a) { - assert(&c, aType == a->type); assert(&c, isFloatValue(a)); assert(&c, resType.flavor() != ir::Type::Float); - assert(&c, aType.flavor() == ir::Type::Float); Value* result = value(&c, resType); appendTranslate(&c, lir::Float2Int, - aType.size(), + a->type.size(), static_cast(a), resType.size(), result); return result; } - virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a) + virtual ir::Value* i2f(ir::Type resType, ir::Value* a) { - assert(&c, aType == a->type); assert(&c, isGeneralValue(a)); assert(&c, resType.flavor() == ir::Type::Float); - assert(&c, aType.flavor() != ir::Type::Float); Value* result = value(&c, resType); appendTranslate(&c, lir::Int2Float, - aType.size(), + a->type.size(), static_cast(a), resType.size(), result); diff --git a/src/compile.cpp b/src/compile.cpp index 4e50fad7dc..660a53e908 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4432,11 +4432,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case d2i: { - frame->pushInt(c->f2i(types.f8, types.i4, frame->popLong())); + frame->pushInt(c->f2i(types.i4, frame->popLong())); } break; case d2l: { - frame->pushLong(c->f2i(types.f8, types.i8, frame->popLong())); + frame->pushLong(c->f2i(types.i8, frame->popLong())); } break; case dadd: @@ -4533,11 +4533,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case f2i: { - frame->pushInt(c->f2i(types.f4, types.i4, frame->popInt())); + frame->pushInt(c->f2i(types.i4, frame->popInt())); } break; case f2l: { - frame->pushLong(c->f2i(types.f4, types.i8, frame->popInt())); + frame->pushLong(c->f2i(types.i8, frame->popInt())); } break; case fadd: @@ -4816,11 +4816,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2d: { - frame->pushDouble(c->i2f(types.i4, types.f8, frame->popInt())); + frame->pushDouble(c->i2f(types.f8, frame->popInt())); } break; case i2f: { - frame->pushFloat(c->i2f(types.i4, types.f4, frame->popInt())); + frame->pushFloat(c->i2f(types.f4, frame->popInt())); } break; case i2l: @@ -5321,11 +5321,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case l2d: { - frame->pushDouble(c->i2f(types.i8, types.f8, frame->popLong())); + frame->pushDouble(c->i2f(types.f8, frame->popLong())); } break; case l2f: { - frame->pushFloat(c->i2f(types.i8, types.f4, frame->popLong())); + frame->pushFloat(c->i2f(types.f4, frame->popLong())); } break; case l2i: From 3029bb2d7ee9264efafea1accc0ff80715dd0bad Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 20:02:29 -0600 Subject: [PATCH 61/89] add type asserts in Compiler::truncate --- src/codegen/compiler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 1a17e9f9cd..dc9c6dd79e 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2562,6 +2562,10 @@ class MyCompiler: public Compiler { virtual ir::Value* truncate(ir::Type type, ir::Type srcType, ir::Value* src) { + assert(&c, srcType == src->type); + assert(&c, src->type.flavor() == type.flavor()); + assert(&c, type.flavor() != ir::Type::Float); + assert(&c, type.size() < src->type.size()); Value* dst = value(&c, type); appendMove(&c, lir::Move, From e3d01746e8be64910df4f005398bf18213945472 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 20:04:43 -0600 Subject: [PATCH 62/89] remove redundant Compiler::truncate srcType parameter --- include/avian/codegen/compiler.h | 3 +-- src/codegen/compiler.cpp | 7 +++---- src/compile.cpp | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index fb34919a03..fb10b3a680 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -110,8 +110,7 @@ class Compiler { ir::Type truncateType, ir::Value* src) = 0; - virtual ir::Value* truncate(ir::Type type, ir::Type srcType, ir::Value* src) - = 0; + virtual ir::Value* truncate(ir::Type type, ir::Value* src) = 0; virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) = 0; virtual ir::Value* load(ir::SignExtendMode signExtend, diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index dc9c6dd79e..e833a1d591 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2560,17 +2560,16 @@ class MyCompiler: public Compiler { static_cast(index), handler); } - virtual ir::Value* truncate(ir::Type type, ir::Type srcType, ir::Value* src) + virtual ir::Value* truncate(ir::Type type, ir::Value* src) { - assert(&c, srcType == src->type); assert(&c, src->type.flavor() == type.flavor()); assert(&c, type.flavor() != ir::Type::Float); assert(&c, type.size() < src->type.size()); Value* dst = value(&c, type); appendMove(&c, lir::Move, - srcType.size(), - srcType.size(), + src->type.size(), + src->type.size(), static_cast(src), type.size(), dst); diff --git a/src/compile.cpp b/src/compile.cpp index 660a53e908..cc83db899d 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -5329,7 +5329,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case l2i: - frame->pushInt(c->truncate(types.i4, types.i8, frame->popLong())); + frame->pushInt(c->truncate(types.i4, frame->popLong())); break; case ladd: From f6bc51647e488ae3267c2f901fec022a7a027fcf Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 20:10:55 -0600 Subject: [PATCH 63/89] add type assert in Compiler::store, fix ensuing problems --- src/codegen/compiler.cpp | 1 + src/compile.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index e833a1d591..aa1eecdfe9 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2595,6 +2595,7 @@ class MyCompiler: public Compiler { virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) { + assert(&c, srcType == src->type); assert(&c, srcType.flavor() == src->type.flavor()); assert(&c, srcType.flavor() == dst->type.flavor()); assert(&c, diff --git a/src/compile.cpp b/src/compile.cpp index cc83db899d..ec8afa02e0 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3790,7 +3790,7 @@ intrinsic(MyThread* t, Frame* frame, object target) ir::Value* value = frame->popInt(); ir::Value* address = popLongAddress(frame); frame->popObject(); - c->store(types.address, value, c->memory(address, types.i1)); + c->store(types.i4, value, c->memory(address, types.i1)); return true; } else if ((MATCH(methodName(t, target), "getShort") and MATCH(methodSpec(t, target), "(J)S")) @@ -3810,7 +3810,7 @@ intrinsic(MyThread* t, Frame* frame, object target) ir::Value* value = frame->popInt(); ir::Value* address = popLongAddress(frame); frame->popObject(); - c->store(types.address, value, c->memory(address, types.i2)); + c->store(types.i4, value, c->memory(address, types.i2)); return true; } else if ((MATCH(methodName(t, target), "getInt") and MATCH(methodSpec(t, target), "(J)I")) @@ -4257,20 +4257,20 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case iastore: - c->store(types.address, + c->store(types.i4, value, c->memory(array, types.i4, TargetArrayBody, index)); break; case bastore: - c->store(types.address, + c->store(types.i4, value, c->memory(array, types.i1, TargetArrayBody, index)); break; case castore: case sastore: - c->store(types.address, + c->store(types.i4, value, c->memory(array, types.i2, TargetArrayBody, index)); break; From 33d946d249dede2df0cefccab746ea00ad4fa86c Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 20:16:19 -0600 Subject: [PATCH 64/89] remove redundant Compiler::store srcType parameter --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 14 ++++------- src/compile.cpp | 41 +++++++++----------------------- 3 files changed, 17 insertions(+), 40 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index fb10b3a680..7bd636f1b0 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -112,7 +112,7 @@ class Compiler { virtual ir::Value* truncate(ir::Type type, ir::Value* src) = 0; - virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) = 0; + virtual void store(ir::Value* src, ir::Value* dst) = 0; virtual ir::Value* load(ir::SignExtendMode signExtend, ir::Value* src, ir::Type dstType) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index aa1eecdfe9..00fc25a5bb 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2593,18 +2593,14 @@ class MyCompiler: public Compiler { return dst; } - virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) + virtual void store(ir::Value* src, ir::Value* dst) { - assert(&c, srcType == src->type); - assert(&c, srcType.flavor() == src->type.flavor()); - assert(&c, srcType.flavor() == dst->type.flavor()); - assert(&c, - srcType.flavor() != ir::Type::Float || srcType.size() - == src->type.size()); + assert(&c, src->type.flavor() == dst->type.flavor()); + appendMove(&c, lir::Move, - srcType.size(), - srcType.size(), + src->type.size(), + src->type.size(), static_cast(src), dst->type.size(), static_cast(dst)); diff --git a/src/compile.cpp b/src/compile.cpp index ec8afa02e0..65ec85740f 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3292,7 +3292,6 @@ void compileDirectInvoke(MyThread* t, trace); c->store( - types.address, frame->absoluteAddressOperand(returnAddressPromise), c->memory( c->threadRegister(), types.address, TARGET_THREAD_TAILADDRESS)); @@ -3790,7 +3789,7 @@ intrinsic(MyThread* t, Frame* frame, object target) ir::Value* value = frame->popInt(); ir::Value* address = popLongAddress(frame); frame->popObject(); - c->store(types.i4, value, c->memory(address, types.i1)); + c->store(value, c->memory(address, types.i1)); return true; } else if ((MATCH(methodName(t, target), "getShort") and MATCH(methodSpec(t, target), "(J)S")) @@ -3810,7 +3809,7 @@ intrinsic(MyThread* t, Frame* frame, object target) ir::Value* value = frame->popInt(); ir::Value* address = popLongAddress(frame); frame->popObject(); - c->store(types.i4, value, c->memory(address, types.i2)); + c->store(value, c->memory(address, types.i2)); return true; } else if ((MATCH(methodName(t, target), "getInt") and MATCH(methodSpec(t, target), "(J)I")) @@ -3834,7 +3833,7 @@ intrinsic(MyThread* t, Frame* frame, object target) frame->popObject(); ir::Type type = MATCH(methodName(t, target), "putInt") ? types.i4 : types.f4; - c->store(type, value, c->memory(address, type)); + c->store(value, c->memory(address, type)); return true; } else if ((MATCH(methodName(t, target), "getLong") and MATCH(methodSpec(t, target), "(J)J")) @@ -3858,7 +3857,7 @@ intrinsic(MyThread* t, Frame* frame, object target) frame->popObject(); ir::Type type = MATCH(methodName(t, target), "putLong") ? types.i8 : types.f8; - c->store(type, value, c->memory(address, type)); + c->store(value, c->memory(address, type)); return true; } else if (MATCH(methodName(t, target), "getAddress") and MATCH(methodSpec(t, target), "(J)J")) @@ -3875,7 +3874,7 @@ intrinsic(MyThread* t, Frame* frame, object target) ir::Value* value = frame->popLong(); ir::Value* address = popLongAddress(frame); frame->popObject(); - c->store(types.i8, value, c->memory(address, types.address)); + c->store(value, c->memory(address, types.address)); return true; } } @@ -4251,40 +4250,28 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case fastore: - c->store(types.f4, - value, - c->memory(array, types.f4, TargetArrayBody, index)); + c->store(value, c->memory(array, types.f4, TargetArrayBody, index)); break; case iastore: - c->store(types.i4, - value, - c->memory(array, types.i4, TargetArrayBody, index)); + c->store(value, c->memory(array, types.i4, TargetArrayBody, index)); break; case bastore: - c->store(types.i4, - value, - c->memory(array, types.i1, TargetArrayBody, index)); + c->store(value, c->memory(array, types.i1, TargetArrayBody, index)); break; case castore: case sastore: - c->store(types.i4, - value, - c->memory(array, types.i2, TargetArrayBody, index)); + c->store(value, c->memory(array, types.i2, TargetArrayBody, index)); break; case dastore: - c->store(types.f8, - value, - c->memory(array, types.f8, TargetArrayBody, index)); + c->store(value, c->memory(array, types.f8, TargetArrayBody, index)); break; case lastore: - c->store(types.i8, - value, - c->memory(array, types.i8, TargetArrayBody, index)); + c->store(value, c->memory(array, types.i8, TargetArrayBody, index)); break; } } break; @@ -5827,7 +5814,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ByteField: case BooleanField: c->store( - types.i4, value, c->memory(table, types.i1, targetFieldOffset(context, field))); break; @@ -5835,35 +5821,30 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case CharField: case ShortField: c->store( - types.i4, value, c->memory(table, types.i2, targetFieldOffset(context, field))); break; case FloatField: c->store( - types.f4, value, c->memory(table, types.f4, targetFieldOffset(context, field))); break; case IntField: c->store( - types.i4, value, c->memory(table, types.i4, targetFieldOffset(context, field))); break; case DoubleField: c->store( - types.f8, value, c->memory(table, types.f8, targetFieldOffset(context, field))); break; case LongField: c->store( - types.i8, value, c->memory(table, types.i8, targetFieldOffset(context, field))); break; From e3354617a622f99769fdc0b8f54898b4b4b764f0 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 20:31:44 -0600 Subject: [PATCH 65/89] add type asserts in Compiler::condJump --- src/codegen/compiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 00fc25a5bb..e5f4ddc5b3 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2634,8 +2634,8 @@ class MyCompiler: public Compiler { (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or( isFloatBranch(op) and isFloatValue(a) and isFloatValue(b))); - // assert(&c, type.flavor() == a->type.flavor()); - // assert(&c, type.flavor() == b->type.flavor()); + assert(&c, type == a->type); + assert(&c, type == b->type); assert(&c, address->type == ir::Type(ir::Type::Integer, TargetBytesPerWord)); From b14709c54c24ca639691775970d7b0b82e2b5dd7 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 20:34:46 -0600 Subject: [PATCH 66/89] remove redundant Compiler::condJump type parameter --- include/avian/codegen/compiler.h | 1 - src/codegen/compiler.cpp | 6 ++---- src/compile.cpp | 25 ++++++++++--------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 7bd636f1b0..07e7376e8c 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -118,7 +118,6 @@ class Compiler { ir::Type dstType) = 0; virtual void condJump(lir::TernaryOperation op, - ir::Type type, ir::Value* a, ir::Value* b, ir::Value* address) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index e5f4ddc5b3..3b570b8381 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2625,7 +2625,6 @@ class MyCompiler: public Compiler { } virtual void condJump(lir::TernaryOperation op, - ir::Type type, ir::Value* a, ir::Value* b, ir::Value* address) @@ -2634,14 +2633,13 @@ class MyCompiler: public Compiler { (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or( isFloatBranch(op) and isFloatValue(a) and isFloatValue(b))); - assert(&c, type == a->type); - assert(&c, type == b->type); + assert(&c, a->type == b->type); assert(&c, address->type == ir::Type(ir::Type::Integer, TargetBytesPerWord)); appendBranch(&c, op, - type.size(), + a->type.size(), static_cast(a), static_cast(b), static_cast(address)); diff --git a/src/compile.cpp b/src/compile.cpp index 65ec85740f..0047bacd39 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3614,7 +3614,6 @@ bool integerBranch(MyThread* t, Frame* frame, object code, unsigned& ip, - ir::Type type, ir::Value* a, ir::Value* b, unsigned* newIpp) @@ -3638,7 +3637,7 @@ bool integerBranch(MyThread* t, case ifge: case iflt: case ifle: - c->condJump(toCompilerJumpOp(t, instruction), type, a, b, target); + c->condJump(toCompilerJumpOp(t, instruction), a, b, target); break; default: @@ -3692,7 +3691,6 @@ bool floatBranch(MyThread* t, Frame* frame, object code, unsigned& ip, - ir::Type type, bool lessIfUnordered, ir::Value* a, ir::Value* b, @@ -3718,7 +3716,6 @@ bool floatBranch(MyThread* t, case iflt: case ifle: c->condJump(toCompilerFloatJumpOp(t, instruction, lessIfUnordered), - type, a, b, target); @@ -4442,7 +4439,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = frame->popLong(); ir::Value* b = frame->popLong(); - if (floatBranch(t, frame, code, ip, types.f8, false, a, b, &newIp)) { + if (floatBranch(t, frame, code, ip, false, a, b, &newIp)) { goto branch; } else { frame->pushInt(c->call( @@ -4462,7 +4459,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = frame->popLong(); ir::Value* b = frame->popLong(); - if (floatBranch(t, frame, code, ip, types.f8, true, a, b, &newIp)) { + if (floatBranch(t, frame, code, ip, true, a, b, &newIp)) { goto branch; } else { frame->pushInt(c->call( @@ -4543,7 +4540,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = frame->popInt(); ir::Value* b = frame->popInt(); - if (floatBranch(t, frame, code, ip, types.f4, false, a, b, &newIp)) { + if (floatBranch(t, frame, code, ip, false, a, b, &newIp)) { goto branch; } else { frame->pushInt(c->call( @@ -4561,7 +4558,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = frame->popInt(); ir::Value* b = frame->popInt(); - if (floatBranch(t, frame, code, ip, types.f4, true, a, b, &newIp)) { + if (floatBranch(t, frame, code, ip, true, a, b, &newIp)) { goto branch; } else { frame->pushInt(c->call( @@ -4889,7 +4886,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* b = frame->popObject(); ir::Value* target = frame->machineIpValue(newIp); - c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target); + c->condJump(toCompilerJumpOp(t, instruction), a, b, target); } goto branch; case if_icmpeq: @@ -4910,7 +4907,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* b = frame->popInt(); ir::Value* target = frame->machineIpValue(newIp); - c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target); + c->condJump(toCompilerJumpOp(t, instruction), a, b, target); } goto branch; case ifeq: @@ -4932,7 +4929,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = c->constant(0, types.i4); ir::Value* b = frame->popInt(); - c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target); + c->condJump(toCompilerJumpOp(t, instruction), a, b, target); } goto branch; case ifnull: @@ -4949,7 +4946,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* b = frame->popObject(); ir::Value* target = frame->machineIpValue(newIp); - c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target); + c->condJump(toCompilerJumpOp(t, instruction), a, b, target); } goto branch; case iinc: { @@ -5335,7 +5332,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* a = frame->popLong(); ir::Value* b = frame->popLong(); - if (integerBranch(t, frame, code, ip, types.i8, a, b, &newIp)) { + if (integerBranch(t, frame, code, ip, a, b, &newIp)) { goto branch; } else { frame->pushInt( @@ -6061,7 +6058,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* key = frame->popInt(); c->condJump(lir::JumpIfLess, - types.i4, c->constant(bottom, types.i4), key, frame->machineIpValue(defaultIp)); @@ -6161,7 +6157,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->restoreState(s->state); c->condJump(lir::JumpIfGreater, - types.i4, c->constant(s->top, types.i4), s->key, frame->machineIpValue(s->defaultIp)); From a0443f0ef1ca9a01d09e1623bd2de458a6c17857 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 20:40:11 -0600 Subject: [PATCH 67/89] add type asserts in Compiler::unaryOp --- src/codegen/compiler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 3b570b8381..e0fde700bb 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2681,6 +2681,7 @@ class MyCompiler: public Compiler { ir::Type type, ir::Value* a) { + assert(&c, a->type == type); assert(&c, (isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op) and isFloatValue(a))); From 008bb6b86e8e8a7706224448042ab1dd881d2ae9 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 20:41:54 -0600 Subject: [PATCH 68/89] remove redundant Compiler::unaryOp type parameter --- include/avian/codegen/compiler.h | 1 - src/codegen/compiler.cpp | 4 +--- src/compile.cpp | 19 ++++++++----------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 07e7376e8c..acf58f7029 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -130,7 +130,6 @@ class Compiler { ir::Value* a, ir::Value* b) = 0; virtual ir::Value* unaryOp(lir::BinaryOperation op, - ir::Type type, ir::Value* a) = 0; virtual void nullaryOp(lir::Operation op) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index e0fde700bb..401a6f965d 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2678,16 +2678,14 @@ class MyCompiler: public Compiler { } virtual ir::Value* unaryOp(lir::BinaryOperation op, - ir::Type type, ir::Value* a) { - assert(&c, a->type == type); assert(&c, (isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op) and isFloatValue(a))); Value* result = value(&c, a->type); appendTranslate( - &c, op, type.size(), static_cast(a), type.size(), result); + &c, op, a->type.size(), static_cast(a), a->type.size(), result); return result; } diff --git a/src/compile.cpp b/src/compile.cpp index 0047bacd39..c30954549c 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -3754,19 +3754,17 @@ intrinsic(MyThread* t, Frame* frame, object target) if (MATCH(methodName(t, target), "sqrt") and MATCH(methodSpec(t, target), "(D)D")) { - frame->pushDouble( - c->unaryOp(lir::FloatSquareRoot, types.f8, frame->popLong())); + frame->pushDouble(c->unaryOp(lir::FloatSquareRoot, frame->popLong())); return true; } else if (MATCH(methodName(t, target), "abs")) { if (MATCH(methodSpec(t, target), "(I)I")) { - frame->pushInt(c->unaryOp(lir::Absolute, types.i4, frame->popInt())); + frame->pushInt(c->unaryOp(lir::Absolute, frame->popInt())); return true; } else if (MATCH(methodSpec(t, target), "(J)J")) { - frame->pushLong(c->unaryOp(lir::Absolute, types.i8, frame->popLong())); + frame->pushLong(c->unaryOp(lir::Absolute, frame->popLong())); return true; } else if (MATCH(methodSpec(t, target), "(F)F")) { - frame->pushFloat( - c->unaryOp(lir::FloatAbsolute, types.f4, frame->popInt())); + frame->pushFloat(c->unaryOp(lir::FloatAbsolute, frame->popInt())); return true; } } @@ -4484,8 +4482,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case dneg: { - frame->pushDouble( - c->unaryOp(lir::FloatNegate, types.f8, frame->popLong())); + frame->pushDouble(c->unaryOp(lir::FloatNegate, frame->popLong())); } break; case dup: @@ -4585,7 +4582,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case fneg: { - frame->pushFloat(c->unaryOp(lir::FloatNegate, types.f4, frame->popInt())); + frame->pushFloat(c->unaryOp(lir::FloatNegate, frame->popInt())); } break; case getfield: @@ -4999,7 +4996,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case ineg: { - frame->pushInt(c->unaryOp(lir::Negate, types.i4, frame->popInt())); + frame->pushInt(c->unaryOp(lir::Negate, frame->popInt())); } break; case instanceof: { @@ -5475,7 +5472,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case lneg: - frame->pushLong(c->unaryOp(lir::Negate, types.i8, frame->popLong())); + frame->pushLong(c->unaryOp(lir::Negate, frame->popLong())); break; case lookupswitch: { From d67820054ee8562fd861ca1bd0694442c824565f Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 20:52:02 -0600 Subject: [PATCH 69/89] add type asserts in appendCombine and appendTranslate --- src/codegen/compiler.cpp | 4 +- src/codegen/compiler/event.cpp | 102 +++++++++++++++++++-------------- src/compile.cpp | 13 +++-- 3 files changed, 67 insertions(+), 52 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 401a6f965d..d83acf88b7 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2668,9 +2668,9 @@ class MyCompiler: public Compiler { appendCombine(&c, op, - type.size(), + a->type.size(), static_cast(a), - type.size(), + b->type.size(), static_cast(b), type.size(), result); diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 0308a07cc9..90a2f1fef7 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -1008,29 +1008,32 @@ class CombineEvent: public Event { Value* resultValue; }; -void -appendCombine(Context* c, lir::TernaryOperation type, - unsigned firstSize, Value* firstValue, - unsigned secondSize, Value* secondValue, - unsigned resultSize, Value* resultValue) +void appendCombine(Context* c, + lir::TernaryOperation op, + unsigned firstSize, + Value* firstValue, + unsigned secondSize, + Value* secondValue, + unsigned resultSize, + Value* resultValue) { + assert(c, firstSize == firstValue->type.size()); + assert(c, secondSize == secondValue->type.size()); + assert(c, resultSize == resultValue->type.size()); bool thunk; OperandMask firstMask; OperandMask secondMask; - c->arch->planSource(type, - firstSize, firstMask, - secondSize, secondMask, - resultSize, - &thunk); + c->arch->planSource( + op, firstSize, firstMask, secondSize, secondMask, resultSize, &thunk); if (thunk) { FixedSliceStack slice; size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; - intptr_t handler = c->client->getThunk - (type, firstSize, resultSize, &threadParameter); + intptr_t handler + = c->client->getThunk(op, firstSize, resultSize, &threadParameter); unsigned stackSize = ceilingDivide(secondSize, vm::TargetBytesPerWord) + ceilingDivide(firstSize, vm::TargetBytesPerWord); @@ -1063,17 +1066,19 @@ appendCombine(Context* c, lir::TernaryOperation type, resultSize, slice); } else { - append - (c, new(c->zone) - CombineEvent - (c, type, - firstSize, firstValue, - secondSize, secondValue, - resultSize, resultValue, - SiteMask::lowPart(firstMask), - SiteMask::highPart(firstMask), - SiteMask::lowPart(secondMask), - SiteMask::highPart(secondMask))); + append(c, + new (c->zone) CombineEvent(c, + op, + firstSize, + firstValue, + secondSize, + secondValue, + resultSize, + resultValue, + SiteMask::lowPart(firstMask), + SiteMask::highPart(firstMask), + SiteMask::lowPart(secondMask), + SiteMask::highPart(secondMask))); } } @@ -1155,15 +1160,20 @@ class TranslateEvent: public Event { SiteMask resultHighMask; }; -void -appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, - Value* firstValue, unsigned resultSize, Value* resultValue) +void appendTranslate(Context* c, + lir::BinaryOperation op, + unsigned firstSize, + Value* firstValue, + unsigned resultSize, + Value* resultValue) { + assert(c, firstSize == firstValue->type.size()); + assert(c, resultSize == resultValue->type.size()); + bool thunk; OperandMask first; - c->arch->planSource(type, firstSize, first, - resultSize, &thunk); + c->arch->planSource(op, firstSize, first, resultSize, &thunk); if (thunk) { size_t stackBase = c->stack ? c->stack->index + 1 : 0; @@ -1175,23 +1185,27 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, stackBase, slice); - appendCall(c, - value(c, - ir::Type(ir::Type::Address, vm::TargetBytesPerWord), - constantSite( - c, c->client->getThunk(type, firstSize, resultSize))), - ir::NativeCallingConvention, - 0, - 0, - resultValue, - resultSize, - slice); + appendCall( + c, + value(c, + ir::Type(ir::Type::Address, vm::TargetBytesPerWord), + constantSite(c, c->client->getThunk(op, firstSize, resultSize))), + ir::NativeCallingConvention, + 0, + 0, + resultValue, + resultSize, + slice); } else { - append(c, new(c->zone) - TranslateEvent - (c, type, firstSize, firstValue, resultSize, resultValue, - SiteMask::lowPart(first), - SiteMask::highPart(first))); + append(c, + new (c->zone) TranslateEvent(c, + op, + firstSize, + firstValue, + resultSize, + resultValue, + SiteMask::lowPart(first), + SiteMask::highPart(first))); } } diff --git a/src/compile.cpp b/src/compile.cpp index c30954549c..d35d936a39 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -5178,12 +5178,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* instance = c->peek(1, parameterFootprint - 1); frame->stackCall( - c->memory(c->binaryOp(lir::And, - types.address, - c->constant(TargetPointerMask, types.i4), - c->memory(instance, types.object)), - types.object, - offset), + c->memory( + c->binaryOp(lir::And, + types.address, + c->constant(TargetPointerMask, types.address), + c->memory(instance, types.object)), + types.object, + offset), target, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0)); From 148d35bab51ce8f75a99767febdc0a314e0c5136 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 21:02:43 -0600 Subject: [PATCH 70/89] remove redundant size parameters to appendCombine and appendTranslate --- src/codegen/compiler.cpp | 11 +-- src/codegen/compiler/event.cpp | 142 ++++++++++++++++----------------- src/codegen/compiler/event.h | 10 +-- 3 files changed, 73 insertions(+), 90 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index d83acf88b7..c5d65a9cf7 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2668,11 +2668,8 @@ class MyCompiler: public Compiler { appendCombine(&c, op, - a->type.size(), static_cast(a), - b->type.size(), static_cast(b), - type.size(), result); return result; } @@ -2685,7 +2682,7 @@ class MyCompiler: public Compiler { and isFloatValue(a))); Value* result = value(&c, a->type); appendTranslate( - &c, op, a->type.size(), static_cast(a), a->type.size(), result); + &c, op, static_cast(a), result); return result; } @@ -2696,9 +2693,7 @@ class MyCompiler: public Compiler { Value* result = value(&c, resType); appendTranslate(&c, lir::Float2Float, - a->type.size(), static_cast(a), - resType.size(), result); return result; } @@ -2710,9 +2705,7 @@ class MyCompiler: public Compiler { Value* result = value(&c, resType); appendTranslate(&c, lir::Float2Int, - a->type.size(), static_cast(a), - resType.size(), result); return result; } @@ -2724,9 +2717,7 @@ class MyCompiler: public Compiler { Value* result = value(&c, resType); appendTranslate(&c, lir::Int2Float, - a->type.size(), static_cast(a), - resType.size(), result); return result; } diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 90a2f1fef7..61d94b436a 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -901,26 +901,26 @@ Site* getTarget(Context* c, Value* value, Value* result, const SiteMask& resultM class CombineEvent: public Event { public: CombineEvent(Context* c, lir::TernaryOperation type, - unsigned firstSize, Value* firstValue, - unsigned secondSize, Value* secondValue, - unsigned resultSize, Value* resultValue, + Value* firstValue, + Value* secondValue, + Value* resultValue, const SiteMask& firstLowMask, const SiteMask& firstHighMask, const SiteMask& secondLowMask, const SiteMask& secondHighMask): - Event(c), type(type), firstSize(firstSize), firstValue(firstValue), - secondSize(secondSize), secondValue(secondValue), resultSize(resultSize), + Event(c), type(type), firstValue(firstValue), + secondValue(secondValue), resultValue(resultValue) { - this->addReads(c, firstValue, firstSize, firstLowMask, firstHighMask); + this->addReads(c, firstValue, firstValue->type.size(), firstLowMask, firstHighMask); - if (resultSize > vm::TargetBytesPerWord) { + if (resultValue->type.size() > vm::TargetBytesPerWord) { resultValue->grow(c); } bool condensed = c->arch->alwaysCondensed(type); - this->addReads(c, secondValue, secondSize, + this->addReads(c, secondValue, secondValue->type.size(), secondLowMask, condensed ? resultValue : 0, secondHighMask, condensed ? resultValue->nextWord : 0); } @@ -941,23 +941,23 @@ class CombineEvent: public Event { assert(c, secondValue->source->type(c) == secondValue->nextWord->source->type(c)); - freezeSource(c, firstSize, firstValue); + freezeSource(c, firstValue->type.size(), firstValue); OperandMask cMask; c->arch->planDestination (type, - firstSize, + firstValue->type.size(), OperandMask( 1 << firstValue->source->type(c), (static_cast(firstValue->nextWord->source->registerMask(c)) << 32) | static_cast(firstValue->source->registerMask(c))), - secondSize, + secondValue->type.size(), OperandMask( 1 << secondValue->source->type(c), (static_cast(secondValue->nextWord->source->registerMask(c)) << 32) | static_cast(secondValue->source->registerMask(c))), - resultSize, + resultValue->type.size(), cMask); SiteMask resultLowMask = SiteMask::lowPart(cMask); @@ -966,7 +966,7 @@ class CombineEvent: public Event { Site* low = getTarget(c, secondValue, resultValue, resultLowMask); unsigned lowSize = low->registerSize(c); Site* high - = (resultSize > lowSize + = (resultValue->type.size() > lowSize ? getTarget(c, secondValue->nextWord, resultValue->nextWord, resultHighMask) : low); @@ -976,75 +976,72 @@ class CombineEvent: public Event { // resultValue, resultValue->nextWord); apply(c, type, - firstSize, firstValue->source, firstValue->nextWord->source, - secondSize, secondValue->source, secondValue->nextWord->source, - resultSize, low, high); + firstValue->type.size(), firstValue->source, firstValue->nextWord->source, + secondValue->type.size(), secondValue->source, secondValue->nextWord->source, + resultValue->type.size(), low, high); - thawSource(c, firstSize, firstValue); + thawSource(c, firstValue->type.size(), firstValue); for (Read* r = reads; r; r = r->eventNext) { popRead(c, this, r->value); } low->thaw(c, secondValue); - if (resultSize > lowSize) { + if (resultValue->type.size() > lowSize) { high->thaw(c, secondValue->nextWord); } if (live(c, resultValue)) { resultValue->addSite(c, low); - if (resultSize > lowSize and live(c, resultValue->nextWord)) { + if (resultValue->type.size() > lowSize and live(c, resultValue->nextWord)) { resultValue->nextWord->addSite(c, high); } } } lir::TernaryOperation type; - unsigned firstSize; Value* firstValue; - unsigned secondSize; Value* secondValue; - unsigned resultSize; Value* resultValue; }; void appendCombine(Context* c, lir::TernaryOperation op, - unsigned firstSize, Value* firstValue, - unsigned secondSize, Value* secondValue, - unsigned resultSize, Value* resultValue) { - assert(c, firstSize == firstValue->type.size()); - assert(c, secondSize == secondValue->type.size()); - assert(c, resultSize == resultValue->type.size()); bool thunk; OperandMask firstMask; OperandMask secondMask; - - c->arch->planSource( - op, firstSize, firstMask, secondSize, secondMask, resultSize, &thunk); + c->arch->planSource(op, + firstValue->type.size(), + firstMask, + secondValue->type.size(), + secondMask, + resultValue->type.size(), + &thunk); if (thunk) { FixedSliceStack slice; size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; - intptr_t handler - = c->client->getThunk(op, firstSize, resultSize, &threadParameter); + intptr_t handler = c->client->getThunk(op, + firstValue->type.size(), + resultValue->type.size(), + &threadParameter); - unsigned stackSize = ceilingDivide(secondSize, vm::TargetBytesPerWord) - + ceilingDivide(firstSize, vm::TargetBytesPerWord); + unsigned stackSize = ceilingDivide(secondValue->type.size(), vm::TargetBytesPerWord) + + ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord); pushSlice(c, - ceilingDivide(secondSize, vm::TargetBytesPerWord), + ceilingDivide(secondValue->type.size(), vm::TargetBytesPerWord), secondValue, stackBase, slice); pushSlice(c, - ceilingDivide(firstSize, vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), firstValue, stackBase, slice); @@ -1063,17 +1060,14 @@ void appendCombine(Context* c, 0, 0, resultValue, - resultSize, + resultValue->type.size(), slice); } else { append(c, new (c->zone) CombineEvent(c, op, - firstSize, firstValue, - secondSize, secondValue, - resultSize, resultValue, SiteMask::lowPart(firstMask), SiteMask::highPart(firstMask), @@ -1084,20 +1078,20 @@ void appendCombine(Context* c, class TranslateEvent: public Event { public: - TranslateEvent(Context* c, lir::BinaryOperation type, unsigned valueSize, - Value* value, unsigned resultSize, Value* resultValue, + TranslateEvent(Context* c, lir::BinaryOperation type, + Value* firstValue, Value* resultValue, const SiteMask& valueLowMask, const SiteMask& valueHighMask): - Event(c), type(type), valueSize(valueSize), resultSize(resultSize), - value(value), resultValue(resultValue) + Event(c), type(type), + firstValue(firstValue), resultValue(resultValue) { bool condensed = c->arch->alwaysCondensed(type); - if (resultSize > vm::TargetBytesPerWord) { + if (resultValue->type.size() > vm::TargetBytesPerWord) { resultValue->grow(c); } - this->addReads(c, value, valueSize, valueLowMask, condensed ? resultValue : 0, + this->addReads(c, firstValue, firstValue->type.size(), valueLowMask, condensed ? resultValue : 0, valueHighMask, condensed ? resultValue->nextWord : 0); } @@ -1106,54 +1100,52 @@ class TranslateEvent: public Event { } virtual void compile(Context* c) { - assert(c, value->source->type(c) == value->nextWord->source->type(c)); + assert(c, firstValue->source->type(c) == firstValue->nextWord->source->type(c)); OperandMask bMask; c->arch->planDestination (type, - valueSize, + firstValue->type.size(), OperandMask( - 1 << value->source->type(c), - (static_cast(value->nextWord->source->registerMask(c)) << 32) - | static_cast(value->source->registerMask(c))), - resultSize, + 1 << firstValue->source->type(c), + (static_cast(firstValue->nextWord->source->registerMask(c)) << 32) + | static_cast(firstValue->source->registerMask(c))), + resultValue->type.size(), bMask); SiteMask resultLowMask = SiteMask::lowPart(bMask); SiteMask resultHighMask = SiteMask::highPart(bMask); - Site* low = getTarget(c, value, resultValue, resultLowMask); + Site* low = getTarget(c, firstValue, resultValue, resultLowMask); unsigned lowSize = low->registerSize(c); Site* high - = (resultSize > lowSize - ? getTarget(c, value->nextWord, resultValue->nextWord, resultHighMask) + = (resultValue->type.size() > lowSize + ? getTarget(c, firstValue->nextWord, resultValue->nextWord, resultHighMask) : low); - apply(c, type, valueSize, value->source, value->nextWord->source, - resultSize, low, high); + apply(c, type, firstValue->type.size(), firstValue->source, firstValue->nextWord->source, + resultValue->type.size(), low, high); for (Read* r = reads; r; r = r->eventNext) { popRead(c, this, r->value); } - low->thaw(c, value); - if (resultSize > lowSize) { - high->thaw(c, value->nextWord); + low->thaw(c, firstValue); + if (resultValue->type.size() > lowSize) { + high->thaw(c, firstValue->nextWord); } if (live(c, resultValue)) { resultValue->addSite(c, low); - if (resultSize > lowSize and live(c, resultValue->nextWord)) { + if (resultValue->type.size() > lowSize and live(c, resultValue->nextWord)) { resultValue->nextWord->addSite(c, high); } } } lir::BinaryOperation type; - unsigned valueSize; - unsigned resultSize; - Value* value; + Value* firstValue; Value* resultValue; Read* resultRead; SiteMask resultLowMask; @@ -1162,25 +1154,24 @@ class TranslateEvent: public Event { void appendTranslate(Context* c, lir::BinaryOperation op, - unsigned firstSize, Value* firstValue, - unsigned resultSize, Value* resultValue) { - assert(c, firstSize == firstValue->type.size()); - assert(c, resultSize == resultValue->type.size()); + assert(c, firstValue->type.size() == firstValue->type.size()); + assert(c, resultValue->type.size() == resultValue->type.size()); bool thunk; OperandMask first; - c->arch->planSource(op, firstSize, first, resultSize, &thunk); + c->arch->planSource( + op, firstValue->type.size(), first, resultValue->type.size(), &thunk); if (thunk) { size_t stackBase = c->stack ? c->stack->index + 1 : 0; FixedSliceStack slice; pushSlice(c, - ceilingDivide(firstSize, vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), firstValue, stackBase, slice); @@ -1189,20 +1180,21 @@ void appendTranslate(Context* c, c, value(c, ir::Type(ir::Type::Address, vm::TargetBytesPerWord), - constantSite(c, c->client->getThunk(op, firstSize, resultSize))), + constantSite( + c, + c->client->getThunk( + op, firstValue->type.size(), resultValue->type.size()))), ir::NativeCallingConvention, 0, 0, resultValue, - resultSize, + resultValue->type.size(), slice); } else { append(c, new (c->zone) TranslateEvent(c, op, - firstSize, firstValue, - resultSize, resultValue, SiteMask::lowPart(first), SiteMask::highPart(first))); diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index 8ed0bc3496..452350d274 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -131,13 +131,13 @@ appendMove(Context* c, lir::BinaryOperation type, unsigned srcSize, void appendCombine(Context* c, lir::TernaryOperation type, - unsigned firstSize, Value* first, - unsigned secondSize, Value* second, - unsigned resultSize, Value* result); + Value* first, + Value* second, + Value* result); void -appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, - Value* first, unsigned resultSize, Value* result); +appendTranslate(Context* c, lir::BinaryOperation type, + Value* first, Value* result); void appendOperation(Context* c, lir::Operation op); From 9282c78549d99dca892d6f6fcae79e0a4352c1a6 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 21:30:31 -0600 Subject: [PATCH 71/89] add type asserts in appendReturn and appendCall --- src/codegen/compiler/event.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 61d94b436a..8a5e9b8231 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -606,6 +606,7 @@ void appendCall(Context* c, unsigned resultSize, util::Slice arguments) { + assert(c, resultSize == result->type.size()); append(c, new (c->zone) CallEvent(c, address, @@ -650,6 +651,7 @@ class ReturnEvent: public Event { }; void appendReturn(Context* c, unsigned size, Value* value) { + assert(c, (value == 0 && size == 0) || size == value->type.size()); append(c, new(c->zone) ReturnEvent(c, size, value)); } From c259faf24aa46196c9f6af768311de1eef737e37 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 21:34:26 -0600 Subject: [PATCH 72/89] remove redundant size parameters to appendReturn and appendCall --- src/codegen/compiler.cpp | 7 +++--- src/codegen/compiler/event.cpp | 42 +++++++++++++++------------------- src/codegen/compiler/event.h | 4 +--- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index c5d65a9cf7..a8e2df9b9d 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2436,7 +2436,6 @@ class MyCompiler: public Compiler { flags, traceHandler, result, - resultType.size(), util::Slice(RUNTIME_ARRAY_BODY(arguments), index)); return result; @@ -2456,7 +2455,6 @@ class MyCompiler: public Compiler { flags, traceHandler, result, - resultType.size(), arguments); assert(&c, c.stack == b); return result; @@ -2464,12 +2462,13 @@ class MyCompiler: public Compiler { virtual void return_(ir::Value* a) { - appendReturn(&c, a->type.size(), static_cast(a)); + assert(&c, a); + appendReturn(&c, static_cast(a)); } virtual void return_() { - appendReturn(&c, 0, 0); + appendReturn(&c, 0); } virtual void initLocal(unsigned footprint, unsigned index, ir::Type type) diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 8a5e9b8231..0511e1542d 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -292,19 +292,17 @@ class CallEvent: public Event { ir::CallingConvention callingConvention, unsigned flags, TraceHandler* traceHandler, - Value* result, - unsigned resultSize, + Value* resultValue, util::Slice arguments) : Event(c), address(address), traceHandler(traceHandler), - result(result), + resultValue(resultValue), returnAddressSurrogate(0), framePointerSurrogate(0), popIndex(0), stackArgumentIndex(0), flags(flags), - resultSize(resultSize), stackArgumentFootprint(callingConvention == ir::AvianCallingConvention ? arguments.count : 0) @@ -573,10 +571,12 @@ class CallEvent: public Event { clean(c, this, stackBefore, localsBefore, reads, popIndex); - if (resultSize and live(c, result)) { - result->addSite(c, registerSite(c, c->arch->returnLow())); - if (resultSize > vm::TargetBytesPerWord and live(c, result->nextWord)) { - result->nextWord->addSite(c, registerSite(c, c->arch->returnHigh())); + if (resultValue->type.size() and live(c, resultValue)) { + resultValue->addSite(c, registerSite(c, c->arch->returnLow())); + if (resultValue->type.size() + > vm::TargetBytesPerWord and live(c, resultValue->nextWord)) { + resultValue->nextWord->addSite(c, + registerSite(c, c->arch->returnHigh())); } } } @@ -587,13 +587,12 @@ class CallEvent: public Event { Value* address; TraceHandler* traceHandler; - Value* result; + Value* resultValue; Value* returnAddressSurrogate; Value* framePointerSurrogate; unsigned popIndex; unsigned stackArgumentIndex; unsigned flags; - unsigned resultSize; unsigned stackArgumentFootprint; }; @@ -603,10 +602,8 @@ void appendCall(Context* c, unsigned flags, TraceHandler* traceHandler, Value* result, - unsigned resultSize, util::Slice arguments) { - assert(c, resultSize == result->type.size()); append(c, new (c->zone) CallEvent(c, address, @@ -614,20 +611,20 @@ void appendCall(Context* c, flags, traceHandler, result, - resultSize, arguments)); } class ReturnEvent: public Event { public: - ReturnEvent(Context* c, unsigned size, Value* value): - Event(c), value(value) + ReturnEvent(Context* c, Value* value) : Event(c), value(value) { if (value) { - this->addReads(c, value, size, - SiteMask::fixedRegisterMask(c->arch->returnLow()), - SiteMask::fixedRegisterMask(c->arch->returnHigh())); + this->addReads(c, + value, + value->type.size(), + SiteMask::fixedRegisterMask(c->arch->returnLow()), + SiteMask::fixedRegisterMask(c->arch->returnHigh())); } } @@ -650,9 +647,9 @@ class ReturnEvent: public Event { Value* value; }; -void appendReturn(Context* c, unsigned size, Value* value) { - assert(c, (value == 0 && size == 0) || size == value->type.size()); - append(c, new(c->zone) ReturnEvent(c, size, value)); +void appendReturn(Context* c, Value* value) +{ + append(c, new (c->zone) ReturnEvent(c, value)); } class MoveEvent: public Event { @@ -1062,7 +1059,6 @@ void appendCombine(Context* c, 0, 0, resultValue, - resultValue->type.size(), slice); } else { append(c, @@ -1190,7 +1186,6 @@ void appendTranslate(Context* c, 0, 0, resultValue, - resultValue->type.size(), slice); } else { append(c, @@ -1562,7 +1557,6 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first 0, 0, result, - 4, slice); appendBranch(c, diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index 452350d274..badba94f64 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -119,11 +119,9 @@ void appendCall(Context* c, unsigned flags, TraceHandler* traceHandler, Value* result, - unsigned resultSize, util::Slice arguments); -void -appendReturn(Context* c, unsigned size, Value* value); +void appendReturn(Context* c, Value* value); void appendMove(Context* c, lir::BinaryOperation type, unsigned srcSize, From 0eda1d7d1129d729e02714f967765e1979f222cc Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 21:39:26 -0600 Subject: [PATCH 73/89] add type asserts in appendBranch --- src/codegen/compiler/event.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 0511e1542d..62248d5adb 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -1517,6 +1517,8 @@ void appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* firstValue, Value* secondValue, Value* addressValue) { + assert(c, size == firstValue->type.size()); + assert(c, size == secondValue->type.size()); bool thunk; OperandMask firstMask; OperandMask secondMask; From e7837c243ee3669881de66119984e8682bf12c93 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 21:45:59 -0600 Subject: [PATCH 74/89] remove redundant size parameter to appendBranch, rename type -> op --- src/codegen/compiler.cpp | 1 - src/codegen/compiler/event.cpp | 349 ++++++++++++++++++++------------- src/codegen/compiler/event.h | 43 ++-- 3 files changed, 244 insertions(+), 149 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index a8e2df9b9d..2aa9e05990 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2638,7 +2638,6 @@ class MyCompiler: public Compiler { appendBranch(&c, op, - a->type.size(), static_cast(a), static_cast(b), static_cast(address)); diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 62248d5adb..90c95dc45b 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -60,10 +60,14 @@ Read* live(Context* c UNUSED, Value* v); void popRead(Context* c, Event* e UNUSED, Value* v); -void -maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, - unsigned srcSelectSize, Value* src, unsigned dstSize, Value* dst, - const SiteMask& dstMask); +void maybeMove(Context* c, + lir::BinaryOperation op, + unsigned srcSize, + unsigned srcSelectSize, + Value* src, + unsigned dstSize, + Value* dst, + const SiteMask& dstMask); Site* maybeMove(Context* c, Value* v, const SiteMask& mask, bool intersectMask, @@ -654,11 +658,22 @@ void appendReturn(Context* c, Value* value) class MoveEvent: public Event { public: - MoveEvent(Context* c, lir::BinaryOperation type, unsigned srcSize, - unsigned srcSelectSize, Value* srcValue, unsigned dstSize, Value* dstValue, - const SiteMask& srcLowMask, const SiteMask& srcHighMask): - Event(c), type(type), srcSize(srcSize), srcSelectSize(srcSelectSize), - srcValue(srcValue), dstSize(dstSize), dstValue(dstValue) + MoveEvent(Context* c, + lir::BinaryOperation op, + unsigned srcSize, + unsigned srcSelectSize, + Value* srcValue, + unsigned dstSize, + Value* dstValue, + const SiteMask& srcLowMask, + const SiteMask& srcHighMask) + : Event(c), + op(op), + srcSize(srcSize), + srcSelectSize(srcSelectSize), + srcValue(srcValue), + dstSize(dstSize), + dstValue(dstValue) { assert(c, srcSelectSize <= srcSize); @@ -684,14 +699,15 @@ class MoveEvent: public Event { virtual void compile(Context* c) { OperandMask dst; - c->arch->planDestination - (type, - srcSelectSize, - OperandMask( - 1 << srcValue->source->type(c), - (static_cast(srcValue->nextWord->source->registerMask(c)) << 32) - | static_cast(srcValue->source->registerMask(c))), - dstSize, dst); + c->arch->planDestination( + op, + srcSelectSize, + OperandMask( + 1 << srcValue->source->type(c), + (static_cast(srcValue->nextWord->source->registerMask(c)) + << 32) | static_cast(srcValue->source->registerMask(c))), + dstSize, + dst); SiteMask dstLowMask = SiteMask::lowPart(dst); SiteMask dstHighMask = SiteMask::highPart(dst); @@ -737,7 +753,13 @@ class MoveEvent: public Event { } else if (srcSelectSize <= vm::TargetBytesPerWord and dstSize <= vm::TargetBytesPerWord) { - maybeMove(c, type, srcSize, srcSelectSize, srcValue, dstSize, dstValue, + maybeMove(c, + op, + srcSize, + srcSelectSize, + srcValue, + dstSize, + dstValue, dstLowMask); } else { assert(c, srcSize == vm::TargetBytesPerWord); @@ -800,7 +822,7 @@ class MoveEvent: public Event { } } - lir::BinaryOperation type; + lir::BinaryOperation op; unsigned srcSize; unsigned srcSelectSize; Value* srcValue; @@ -808,23 +830,31 @@ class MoveEvent: public Event { Value* dstValue; }; -void -appendMove(Context* c, lir::BinaryOperation type, unsigned srcSize, - unsigned srcSelectSize, Value* srcValue, unsigned dstSize, Value* dstValue) +void appendMove(Context* c, + lir::BinaryOperation op, + unsigned srcSize, + unsigned srcSelectSize, + Value* srcValue, + unsigned dstSize, + Value* dstValue) { bool thunk; OperandMask src; - c->arch->planSource - (type, srcSelectSize, src, dstSize, &thunk); + c->arch->planSource(op, srcSelectSize, src, dstSize, &thunk); assert(c, not thunk); - append(c, new(c->zone) - MoveEvent - (c, type, srcSize, srcSelectSize, srcValue, dstSize, dstValue, - SiteMask::lowPart(src), - SiteMask::highPart(src))); + append(c, + new (c->zone) MoveEvent(c, + op, + srcSize, + srcSelectSize, + srcValue, + dstSize, + dstValue, + SiteMask::lowPart(src), + SiteMask::highPart(src))); } @@ -899,17 +929,20 @@ Site* getTarget(Context* c, Value* value, Value* result, const SiteMask& resultM class CombineEvent: public Event { public: - CombineEvent(Context* c, lir::TernaryOperation type, + CombineEvent(Context* c, + lir::TernaryOperation op, Value* firstValue, Value* secondValue, Value* resultValue, const SiteMask& firstLowMask, const SiteMask& firstHighMask, const SiteMask& secondLowMask, - const SiteMask& secondHighMask): - Event(c), type(type), firstValue(firstValue), - secondValue(secondValue), - resultValue(resultValue) + const SiteMask& secondHighMask) + : Event(c), + op(op), + firstValue(firstValue), + secondValue(secondValue), + resultValue(resultValue) { this->addReads(c, firstValue, firstValue->type.size(), firstLowMask, firstHighMask); @@ -917,7 +950,7 @@ class CombineEvent: public Event { resultValue->grow(c); } - bool condensed = c->arch->alwaysCondensed(type); + bool condensed = c->arch->alwaysCondensed(op); this->addReads(c, secondValue, secondValue->type.size(), secondLowMask, condensed ? resultValue : 0, @@ -944,20 +977,24 @@ class CombineEvent: public Event { OperandMask cMask; - c->arch->planDestination - (type, - firstValue->type.size(), - OperandMask( - 1 << firstValue->source->type(c), - (static_cast(firstValue->nextWord->source->registerMask(c)) << 32) + c->arch->planDestination( + op, + firstValue->type.size(), + OperandMask( + 1 << firstValue->source->type(c), + (static_cast( + firstValue->nextWord->source->registerMask(c)) + << 32) | static_cast(firstValue->source->registerMask(c))), - secondValue->type.size(), - OperandMask( - 1 << secondValue->source->type(c), - (static_cast(secondValue->nextWord->source->registerMask(c)) << 32) + secondValue->type.size(), + OperandMask( + 1 << secondValue->source->type(c), + (static_cast( + secondValue->nextWord->source->registerMask(c)) + << 32) | static_cast(secondValue->source->registerMask(c))), - resultValue->type.size(), - cMask); + resultValue->type.size(), + cMask); SiteMask resultLowMask = SiteMask::lowPart(cMask); SiteMask resultHighMask = SiteMask::highPart(cMask); @@ -974,10 +1011,17 @@ class CombineEvent: public Event { // secondValue, secondValue->nextWord, // resultValue, resultValue->nextWord); - apply(c, type, - firstValue->type.size(), firstValue->source, firstValue->nextWord->source, - secondValue->type.size(), secondValue->source, secondValue->nextWord->source, - resultValue->type.size(), low, high); + apply(c, + op, + firstValue->type.size(), + firstValue->source, + firstValue->nextWord->source, + secondValue->type.size(), + secondValue->source, + secondValue->nextWord->source, + resultValue->type.size(), + low, + high); thawSource(c, firstValue->type.size(), firstValue); @@ -998,7 +1042,7 @@ class CombineEvent: public Event { } } - lir::TernaryOperation type; + lir::TernaryOperation op; Value* firstValue; Value* secondValue; Value* resultValue; @@ -1076,14 +1120,15 @@ void appendCombine(Context* c, class TranslateEvent: public Event { public: - TranslateEvent(Context* c, lir::BinaryOperation type, - Value* firstValue, Value* resultValue, + TranslateEvent(Context* c, + lir::BinaryOperation op, + Value* firstValue, + Value* resultValue, const SiteMask& valueLowMask, - const SiteMask& valueHighMask): - Event(c), type(type), - firstValue(firstValue), resultValue(resultValue) + const SiteMask& valueHighMask) + : Event(c), op(op), firstValue(firstValue), resultValue(resultValue) { - bool condensed = c->arch->alwaysCondensed(type); + bool condensed = c->arch->alwaysCondensed(op); if (resultValue->type.size() > vm::TargetBytesPerWord) { resultValue->grow(c); @@ -1101,16 +1146,18 @@ class TranslateEvent: public Event { assert(c, firstValue->source->type(c) == firstValue->nextWord->source->type(c)); OperandMask bMask; - - c->arch->planDestination - (type, - firstValue->type.size(), - OperandMask( - 1 << firstValue->source->type(c), - (static_cast(firstValue->nextWord->source->registerMask(c)) << 32) + + c->arch->planDestination( + op, + firstValue->type.size(), + OperandMask( + 1 << firstValue->source->type(c), + (static_cast( + firstValue->nextWord->source->registerMask(c)) + << 32) | static_cast(firstValue->source->registerMask(c))), - resultValue->type.size(), - bMask); + resultValue->type.size(), + bMask); SiteMask resultLowMask = SiteMask::lowPart(bMask); SiteMask resultHighMask = SiteMask::highPart(bMask); @@ -1122,8 +1169,14 @@ class TranslateEvent: public Event { ? getTarget(c, firstValue->nextWord, resultValue->nextWord, resultHighMask) : low); - apply(c, type, firstValue->type.size(), firstValue->source, firstValue->nextWord->source, - resultValue->type.size(), low, high); + apply(c, + op, + firstValue->type.size(), + firstValue->source, + firstValue->nextWord->source, + resultValue->type.size(), + low, + high); for (Read* r = reads; r; r = r->eventNext) { popRead(c, this, r->value); @@ -1142,7 +1195,7 @@ class TranslateEvent: public Event { } } - lir::BinaryOperation type; + lir::BinaryOperation op; Value* firstValue; Value* resultValue; Read* resultRead; @@ -1341,11 +1394,13 @@ unordered(double a, double b) return not (a >= b or a < b); } -bool -shouldJump(Context* c, lir::TernaryOperation type, unsigned size, int64_t b, - int64_t a) +bool shouldJump(Context* c, + lir::TernaryOperation op, + unsigned size, + int64_t b, + int64_t a) { - switch (type) { + switch (op) { case lir::JumpIfEqual: return a == b; @@ -1403,10 +1458,9 @@ shouldJump(Context* c, lir::TernaryOperation type, unsigned size, int64_t b, } } -lir::TernaryOperation -thunkBranch(Context* c, lir::TernaryOperation type) +lir::TernaryOperation thunkBranch(Context* c, lir::TernaryOperation op) { - switch (type) { + switch (op) { case lir::JumpIfFloatEqual: return lir::JumpIfEqual; @@ -1436,23 +1490,34 @@ thunkBranch(Context* c, lir::TernaryOperation type) class BranchEvent: public Event { public: - BranchEvent(Context* c, lir::TernaryOperation type, unsigned size, - Value* firstValue, Value* secondValue, Value* addressValue, + BranchEvent(Context* c, + lir::TernaryOperation op, + Value* firstValue, + Value* secondValue, + Value* addressValue, const SiteMask& firstLowMask, const SiteMask& firstHighMask, const SiteMask& secondLowMask, - const SiteMask& secondHighMask): - Event(c), type(type), size(size), firstValue(firstValue), secondValue(secondValue), - addressValue(addressValue) + const SiteMask& secondHighMask) + : Event(c), + op(op), + firstValue(firstValue), + secondValue(secondValue), + addressValue(addressValue) { - this->addReads(c, firstValue, size, firstLowMask, firstHighMask); - this->addReads(c, secondValue, size, secondLowMask, secondHighMask); + this->addReads( + c, firstValue, firstValue->type.size(), firstLowMask, firstHighMask); + this->addReads( + c, secondValue, firstValue->type.size(), secondLowMask, secondHighMask); OperandMask dstMask; - c->arch->planDestination(type, - size, OperandMask(0, 0), - size, OperandMask(0, 0), - vm::TargetBytesPerWord, dstMask); + c->arch->planDestination(op, + firstValue->type.size(), + OperandMask(0, 0), + firstValue->type.size(), + OperandMask(0, 0), + vm::TargetBytesPerWord, + dstMask); this->addRead(c, addressValue, SiteMask::lowPart(dstMask)); } @@ -1474,28 +1539,40 @@ class BranchEvent: public Event { int64_t firstConstVal = firstConstant->value->value(); int64_t secondConstVal = secondConstant->value->value(); - if (size > vm::TargetBytesPerWord) { + if (firstValue->type.size() > vm::TargetBytesPerWord) { firstConstVal |= findConstantSite (c, firstValue->nextWord)->value->value() << 32; secondConstVal |= findConstantSite (c, secondValue->nextWord)->value->value() << 32; } - if (shouldJump(c, type, size, firstConstVal, secondConstVal)) { + if (shouldJump(c, + op, + firstValue->type.size(), + firstConstVal, + secondConstVal)) { apply(c, lir::Jump, vm::TargetBytesPerWord, addressValue->source, addressValue->source); } } else { - freezeSource(c, size, firstValue); - freezeSource(c, size, secondValue); + freezeSource(c, firstValue->type.size(), firstValue); + freezeSource(c, firstValue->type.size(), secondValue); freezeSource(c, vm::TargetBytesPerWord, addressValue); - apply(c, type, size, firstValue->source, firstValue->nextWord->source, - size, secondValue->source, secondValue->nextWord->source, - vm::TargetBytesPerWord, addressValue->source, addressValue->source); + apply(c, + op, + firstValue->type.size(), + firstValue->source, + firstValue->nextWord->source, + firstValue->type.size(), + secondValue->source, + secondValue->nextWord->source, + vm::TargetBytesPerWord, + addressValue->source, + addressValue->source); thawSource(c, vm::TargetBytesPerWord, addressValue); - thawSource(c, size, secondValue); - thawSource(c, size, firstValue); + thawSource(c, firstValue->type.size(), secondValue); + thawSource(c, firstValue->type.size(), firstValue); } } @@ -1506,45 +1583,47 @@ class BranchEvent: public Event { virtual bool isBranch() { return true; } - lir::TernaryOperation type; - unsigned size; + lir::TernaryOperation op; Value* firstValue; Value* secondValue; Value* addressValue; }; -void -appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* firstValue, - Value* secondValue, Value* addressValue) +void appendBranch(Context* c, + lir::TernaryOperation op, + Value* firstValue, + Value* secondValue, + Value* addressValue) { - assert(c, size == firstValue->type.size()); - assert(c, size == secondValue->type.size()); bool thunk; OperandMask firstMask; OperandMask secondMask; - c->arch->planSource(type, - size, firstMask, - size, secondMask, - vm::TargetBytesPerWord, &thunk); + c->arch->planSource(op, + firstValue->type.size(), + firstMask, + firstValue->type.size(), + secondMask, + vm::TargetBytesPerWord, + &thunk); if (thunk) { FixedSliceStack slice; size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; - intptr_t handler = c->client->getThunk - (type, size, size, &threadParameter); + intptr_t handler = c->client->getThunk( + op, firstValue->type.size(), firstValue->type.size(), &threadParameter); assert(c, not threadParameter); pushSlice(c, - ceilingDivide(size, vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), secondValue, stackBase, slice); pushSlice(c, - ceilingDivide(size, vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), firstValue, stackBase, slice); @@ -1562,22 +1641,23 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first slice); appendBranch(c, - thunkBranch(c, type), - 4, + thunkBranch(c, op), value(c, ir::Type(ir::Type::Address, vm::TargetBytesPerWord), constantSite(c, static_cast(0))), result, addressValue); } else { - append - (c, new(c->zone) - BranchEvent - (c, type, size, firstValue, secondValue, addressValue, - SiteMask::lowPart(firstMask), - SiteMask::highPart(firstMask), - SiteMask::lowPart(secondMask), - SiteMask::highPart(secondMask))); + append(c, + new (c->zone) BranchEvent(c, + op, + firstValue, + secondValue, + addressValue, + SiteMask::lowPart(firstMask), + SiteMask::highPart(firstMask), + SiteMask::lowPart(secondMask), + SiteMask::highPart(secondMask))); } } @@ -1619,14 +1699,16 @@ clean(Context* c, Event* e, Stack* stack, Local* locals, Read* reads, class JumpEvent: public Event { public: - JumpEvent(Context* c, lir::UnaryOperation type, Value* address, bool exit, - bool cleanLocals): - Event(c), type(type), address(address), exit(exit), - cleanLocals(cleanLocals) + JumpEvent(Context* c, + lir::UnaryOperation op, + Value* address, + bool exit, + bool cleanLocals) + : Event(c), op(op), address(address), exit(exit), cleanLocals(cleanLocals) { bool thunk; OperandMask mask; - c->arch->plan(type, vm::TargetBytesPerWord, mask, &thunk); + c->arch->plan(op, vm::TargetBytesPerWord, mask, &thunk); assert(c, not thunk); @@ -1639,7 +1721,7 @@ class JumpEvent: public Event { virtual void compile(Context* c) { if (not this->isUnreachable()) { - apply(c, type, vm::TargetBytesPerWord, address->source, address->source); + apply(c, op, vm::TargetBytesPerWord, address->source, address->source); } for (Read* r = reads; r; r = r->eventNext) { @@ -1660,14 +1742,19 @@ class JumpEvent: public Event { return exit or this->isUnreachable(); } - lir::UnaryOperation type; + lir::UnaryOperation op; Value* address; bool exit; bool cleanLocals; }; -void appendJump(Context* c, lir::UnaryOperation type, Value* address, bool exit, bool cleanLocals) { - append(c, new(c->zone) JumpEvent(c, type, address, exit, cleanLocals)); +void appendJump(Context* c, + lir::UnaryOperation op, + Value* address, + bool exit, + bool cleanLocals) +{ + append(c, new (c->zone) JumpEvent(c, op, address, exit, cleanLocals)); } class BoundsCheckEvent: public Event { diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index badba94f64..03e21d2bc2 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -123,19 +123,24 @@ void appendCall(Context* c, void appendReturn(Context* c, Value* value); -void -appendMove(Context* c, lir::BinaryOperation type, unsigned srcSize, - unsigned srcSelectSize, Value* src, unsigned dstSize, Value* dst); +void appendMove(Context* c, + lir::BinaryOperation op, + unsigned srcSize, + unsigned srcSelectSize, + Value* src, + unsigned dstSize, + Value* dst); -void -appendCombine(Context* c, lir::TernaryOperation type, - Value* first, - Value* second, - Value* result); +void appendCombine(Context* c, + lir::TernaryOperation op, + Value* first, + Value* second, + Value* result); -void -appendTranslate(Context* c, lir::BinaryOperation type, - Value* first, Value* result); +void appendTranslate(Context* c, + lir::BinaryOperation op, + Value* first, + Value* result); void appendOperation(Context* c, lir::Operation op); @@ -144,13 +149,17 @@ void appendMemory(Context* c, Value* base, int displacement, Value* index, unsigned scale, Value* result); -void -appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first, - Value* second, Value* address); +void appendBranch(Context* c, + lir::TernaryOperation op, + Value* first, + Value* second, + Value* address); -void -appendJump(Context* c, lir::UnaryOperation type, Value* address, bool exit = false, - bool cleanLocals = false); +void appendJump(Context* c, + lir::UnaryOperation op, + Value* address, + bool exit = false, + bool cleanLocals = false); void appendBoundsCheck(Context* c, Value* object, unsigned lengthOffset, From cc4525c31cc1e192ed4491ff56c391a927faf66f Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 21:52:30 -0600 Subject: [PATCH 75/89] add type/footprint assert in Compiler::storeLocal --- src/codegen/compiler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 2aa9e05990..fc79d4b6b5 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2536,6 +2536,7 @@ class MyCompiler: public Compiler { virtual void storeLocal(unsigned footprint, ir::Value* src, unsigned index) { + assert(&c, typeFootprint(src->type) == footprint); compiler::storeLocal(&c, footprint, static_cast(src), index, true); } From 91c5599fc07366bd7b5abe28b409f4495d62b856 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 21:54:10 -0600 Subject: [PATCH 76/89] remove redundant Compiler::storeLocal footprint parameter --- include/avian/codegen/compiler.h | 2 +- src/codegen/compiler.cpp | 5 ++--- src/compile.cpp | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index acf58f7029..4c3d2bcf1c 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -95,7 +95,7 @@ class Compiler { virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0; virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0; - virtual void storeLocal(unsigned footprint, ir::Value* src, unsigned index) + virtual void storeLocal(ir::Value* src, unsigned index) = 0; virtual ir::Value* loadLocal(ir::Type type, unsigned index) = 0; virtual void saveLocals() = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index fc79d4b6b5..4d6d52e1c5 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2534,10 +2534,9 @@ class MyCompiler: public Compiler { linkLocals(&c, e->locals(), newLocals); } - virtual void storeLocal(unsigned footprint, ir::Value* src, unsigned index) + virtual void storeLocal(ir::Value* src, unsigned index) { - assert(&c, typeFootprint(src->type) == footprint); - compiler::storeLocal(&c, footprint, static_cast(src), index, true); + compiler::storeLocal(&c, typeFootprint(&c, src->type), static_cast(src), index, true); } virtual ir::Value* loadLocal(ir::Type type, unsigned index) diff --git a/src/compile.cpp b/src/compile.cpp index d35d936a39..197b5607e4 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1295,8 +1295,8 @@ void storeLocal(Context* context, || value->type.flavor() == ir::Type::Address)) // TODO Temporary hack for Subroutine test!!! || value->type.flavor() == ir::Type::Integer); - context->compiler->storeLocal - (footprint, value, translateLocalIndex(context, footprint, index)); + context->compiler->storeLocal(value, + translateLocalIndex(context, footprint, index)); } avian::util::FixedAllocator* codeAllocator(MyThread* t); From 9a54c50db60900976df5fdd15adb3ea6123197b2 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 22:01:28 -0600 Subject: [PATCH 77/89] make asserts in loadLocal and storeLocal more strict --- src/compile.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 197b5607e4..bf7c7fd759 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1272,13 +1272,7 @@ ir::Value* loadLocal(Context* context, ir::Value* result = context->compiler->loadLocal( type, translateLocalIndex(context, footprint, index)); - assert(context->thread, - (type.flavor() != ir::Type::Object && type == result->type) - || (type.flavor() == ir::Type::Object - && (result->type.flavor() == ir::Type::Object - || result->type.flavor() == ir::Type::Address)) - // TODO Temporary hack for Subroutine test!!! - || result->type.flavor() == ir::Type::Integer); + assert(context->thread, type == result->type); return result; } @@ -1288,13 +1282,7 @@ void storeLocal(Context* context, ir::Value* value, unsigned index) { - assert(context->thread, - (type.flavor() != ir::Type::Object && type == value->type) - || (type.flavor() == ir::Type::Object - && (value->type.flavor() == ir::Type::Object - || value->type.flavor() == ir::Type::Address)) - // TODO Temporary hack for Subroutine test!!! - || value->type.flavor() == ir::Type::Integer); + assert(context->thread, type == value->type); context->compiler->storeLocal(value, translateLocalIndex(context, footprint, index)); } @@ -2099,10 +2087,10 @@ class Frame { void startSubroutine(unsigned ip, unsigned returnAddress) { + // Push a dummy value to the stack, representing the return address (which + // we don't need, since we're expanding everything statically). // TODO: in the future, push a value that we can track through type checking - pushAddress(); // push a dummy value to the stack, representing the return - // address (which we don't need, since we're expanding - // everything statically) + pushObject(c->constant(0, types.object)); if (DebugInstructions) { fprintf(stderr, "startSubroutine %u %u\n", ip, returnAddress); From b6a3ed763c86fad4d228bf86cf2dd80659def9e8 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 22:14:49 -0600 Subject: [PATCH 78/89] add assert in Compiler::initLocal and fix ensuing problems --- src/codegen/compiler.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 4d6d52e1c5..fa5ba3d78f 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2471,10 +2471,28 @@ class MyCompiler: public Compiler { appendReturn(&c, 0); } + void initLocalPart(unsigned index, ir::Type type) + { + Value* v = value(&c, type); + + if (DebugFrame) { + fprintf(stderr, + "init local %p at %d (%d)\n", + v, + index, + frameIndex(&c, index)); + } + + appendFrameSite(&c, v, frameIndex(&c, index)); + + Local* local = c.locals + index; + local->value = v; + v->home = frameIndex(&c, index); + } + virtual void initLocal(unsigned footprint, unsigned index, ir::Type type) { - // TODO: enable the following assertion when possible: - // assert(&c, footprint == typeFootprint(type)); + assert(&c, footprint == typeFootprint(&c, type)); assert(&c, index + footprint <= c.localFootprint); Value* v = value(&c, type); @@ -2493,7 +2511,7 @@ class MyCompiler: public Compiler { } if (TargetBytesPerWord == 4) { - initLocal(1, highIndex, type); + initLocalPart(highIndex, type); Value* next = c.locals[highIndex].value; v->nextWord = next; next->nextWord = v; @@ -2527,7 +2545,7 @@ class MyCompiler: public Compiler { for (int i = 0; i < static_cast(c.localFootprint); ++i) { Local* local = e->locals() + i; if (local->value) { - initLocal(1, i, local->value->type); + initLocalPart(i, local->value->type); } } From 9273d5ca39df26af2a482b5feb41f562e78ab633 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 22:16:22 -0600 Subject: [PATCH 79/89] remove redundant Compiler::initLocal footprint parameter --- include/avian/codegen/compiler.h | 5 ++--- src/codegen/compiler.cpp | 5 +++-- src/compile.cpp | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 4c3d2bcf1c..099ae15ca5 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -93,10 +93,9 @@ class Compiler { virtual void return_(ir::Value* value) = 0; virtual void return_() = 0; - virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0; + virtual void initLocal(unsigned index, ir::Type type) = 0; virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0; - virtual void storeLocal(ir::Value* src, unsigned index) - = 0; + virtual void storeLocal(ir::Value* src, unsigned index) = 0; virtual ir::Value* loadLocal(ir::Type type, unsigned index) = 0; virtual void saveLocals() = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index fa5ba3d78f..019c139eb6 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2490,9 +2490,10 @@ class MyCompiler: public Compiler { v->home = frameIndex(&c, index); } - virtual void initLocal(unsigned footprint, unsigned index, ir::Type type) + virtual void initLocal(unsigned index, ir::Type type) { - assert(&c, footprint == typeFootprint(&c, type)); + unsigned footprint = typeFootprint(&c, type); + assert(&c, index + footprint <= c.localFootprint); Value* v = value(&c, type); diff --git a/src/compile.cpp b/src/compile.cpp index bf7c7fd759..37b0a5f4ec 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -7030,7 +7030,7 @@ compile(MyThread* t, Context* context) unsigned index = methodParameterFootprint(t, context->method); if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { frame.set(--index, Frame::Object); - c->initLocal(1, index, frame.types.object); + c->initLocal(index, frame.types.object); } for (MethodSpecIterator it @@ -7042,29 +7042,29 @@ compile(MyThread* t, Context* context) case 'L': case '[': frame.set(--index, Frame::Object); - c->initLocal(1, index, frame.types.object); + c->initLocal(index, frame.types.object); break; case 'J': frame.set(--index, Frame::Long); frame.set(--index, Frame::Long); - c->initLocal(2, index, frame.types.i8); + c->initLocal(index, frame.types.i8); break; case 'D': frame.set(--index, Frame::Long); frame.set(--index, Frame::Long); - c->initLocal(2, index, frame.types.f8); + c->initLocal(index, frame.types.f8); break; case 'F': frame.set(--index, Frame::Integer); - c->initLocal(1, index, frame.types.f4); + c->initLocal(index, frame.types.f4); break; default: frame.set(--index, Frame::Integer); - c->initLocal(1, index, frame.types.i4); + c->initLocal(index, frame.types.i4); break; } } From 37d104871ceda40533dbf3246332cf9042f7a85d Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 3 May 2014 23:28:27 -0600 Subject: [PATCH 80/89] test line number table generation in subroutines --- src/compile.cpp | 1 - test/Subroutine.java | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/compile.cpp b/src/compile.cpp index 37b0a5f4ec..5a316ff682 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -6431,7 +6431,6 @@ object translateExceptionHandlerTable(MyThread* t, object translateLineNumberTable(MyThread* t, Context* context, intptr_t start) { - // TODO: add line number table entries for subroutines (duplicated code) object oldTable = codeLineNumberTable(t, methodCode(t, context->method)); if (oldTable) { PROTECT(t, oldTable); diff --git a/test/Subroutine.java b/test/Subroutine.java index d566f78095..5fb5bfa223 100644 --- a/test/Subroutine.java +++ b/test/Subroutine.java @@ -253,6 +253,16 @@ public class Subroutine { return true; } + private static int test6(boolean predicate) { + try { + if (predicate) { + return -2; + } + } finally { + return new Throwable().getStackTrace()[0].getLineNumber(); + } + } + public static void main(String[] args) throws Exception { test(false, false); test(false, true); @@ -311,6 +321,15 @@ public class Subroutine { (null, new Object[0]); stackMap(new Object()); + + { + int f = test6(false); + int t = test6(true); + System.out.println("line: " + f); + expect(f > 0); + expect(f == t); + } + } private static class DummyException extends RuntimeException { } From 7abbace8fb47f9a98f5323c7aaad21346bcde195 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Mon, 5 May 2014 10:49:50 -0600 Subject: [PATCH 81/89] replace Frame::StackType with ir::Type --- src/compile.cpp | 161 ++++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 81 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 5a316ff682..31fb1d74ce 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1350,13 +1350,7 @@ int methodReferenceReturnCode(Thread* t, object reference) class Frame { public: - enum StackType { - Integer, - Long, - Object - }; - - Frame(Context* context, uint8_t* stackMap) + Frame(Context* context, ir::Type* stackMap) : context(context), t(context->thread), c(context->compiler), @@ -1367,10 +1361,12 @@ class Frame { level(0), types(TargetBytesPerWord) { - memset(stackMap, 0, codeMaxStack(t, methodCode(t, context->method))); + memset(stackMap, + 0, + codeMaxStack(t, methodCode(t, context->method)) * sizeof(ir::Type)); } - Frame(Frame* f, uint8_t* stackMap) + Frame(Frame* f, ir::Type* stackMap) : context(f->context), t(context->thread), c(context->compiler), @@ -1381,8 +1377,9 @@ class Frame { level(f->level + 1), types(TargetBytesPerWord) { - memcpy(stackMap, f->stackMap, codeMaxStack - (t, methodCode(t, context->method))); + memcpy(stackMap, + f->stackMap, + codeMaxStack(t, methodCode(t, context->method)) * sizeof(ir::Type)); if (level > 1) { context->eventLog.append(PushContextEvent); @@ -1442,10 +1439,11 @@ class Frame { return localSize() + stackSize(); } - void set(unsigned index, uint8_t type) { + void set(unsigned index, ir::Type type) + { assert(t, index < frameSize()); - if (type == Object) { + if (type == types.object) { context->eventLog.append(MarkEvent); context->eventLog.append2(index); } else { @@ -1459,7 +1457,8 @@ class Frame { } } - uint8_t get(unsigned index) { + ir::Type get(unsigned index) + { assert(t, index < frameSize()); int si = index - localSize(); assert(t, si >= 0); @@ -1468,25 +1467,25 @@ class Frame { void pushedInt() { assert(t, sp + 1 <= frameSize()); - set(sp++, Integer); + set(sp++, types.i4); } void pushedLong() { assert(t, sp + 2 <= frameSize()); - set(sp++, Long); - set(sp++, Long); + set(sp++, types.i8); + set(sp++, types.i8); } void pushedObject() { assert(t, sp + 1 <= frameSize()); - set(sp++, Object); + set(sp++, types.object); } void popped(unsigned count) { assert(t, sp >= count); assert(t, sp - count >= localSize()); while (count) { - set(--sp, Integer); + set(--sp, types.i4); -- count; } } @@ -1494,39 +1493,39 @@ class Frame { void poppedInt() { assert(t, sp >= 1); assert(t, sp - 1 >= localSize()); - assert(t, get(sp - 1) == Integer); + assert(t, get(sp - 1) == types.i4); -- sp; } void poppedLong() { assert(t, sp >= 1); assert(t, sp - 2 >= localSize()); - assert(t, get(sp - 1) == Long); - assert(t, get(sp - 2) == Long); + assert(t, get(sp - 1) == types.i8); + assert(t, get(sp - 2) == types.i8); sp -= 2; } void poppedObject() { assert(t, sp >= 1); assert(t, sp - 1 >= localSize()); - assert(t, get(sp - 1) == Object); - set(--sp, Integer); + assert(t, get(sp - 1) == types.object); + set(--sp, types.i4); } void storedInt(unsigned index) { assert(t, index < localSize()); - set(index, Integer); + set(index, types.i4); } void storedLong(unsigned index) { assert(t, index + 1 < localSize()); - set(index, Long); - set(index + 1, Long); + set(index, types.i8); + set(index + 1, types.i8); } void storedObject(unsigned index) { assert(t, index < localSize()); - set(index, Object); + set(index, types.object); } void dupped() { @@ -1540,8 +1539,8 @@ class Frame { assert(t, sp + 1 <= frameSize()); assert(t, sp - 2 >= localSize()); - uint8_t b2 = get(sp - 2); - uint8_t b1 = get(sp - 1); + ir::Type b2 = get(sp - 2); + ir::Type b1 = get(sp - 1); set(sp - 1, b2); set(sp - 2, b1); @@ -1554,9 +1553,9 @@ class Frame { assert(t, sp + 1 <= frameSize()); assert(t, sp - 3 >= localSize()); - uint8_t b3 = get(sp - 3); - uint8_t b2 = get(sp - 2); - uint8_t b1 = get(sp - 1); + ir::Type b3 = get(sp - 3); + ir::Type b2 = get(sp - 2); + ir::Type b1 = get(sp - 1); set(sp - 2, b3); set(sp - 1, b2); @@ -1570,8 +1569,8 @@ class Frame { assert(t, sp + 2 <= frameSize()); assert(t, sp - 2 >= localSize()); - uint8_t b2 = get(sp - 2); - uint8_t b1 = get(sp - 1); + ir::Type b2 = get(sp - 2); + ir::Type b1 = get(sp - 1); set(sp, b2); set(sp + 1, b1); @@ -1583,9 +1582,9 @@ class Frame { assert(t, sp + 2 <= frameSize()); assert(t, sp - 3 >= localSize()); - uint8_t b3 = get(sp - 3); - uint8_t b2 = get(sp - 2); - uint8_t b1 = get(sp - 1); + ir::Type b3 = get(sp - 3); + ir::Type b2 = get(sp - 2); + ir::Type b1 = get(sp - 1); set(sp - 1, b3); set(sp - 3, b2); @@ -1600,10 +1599,10 @@ class Frame { assert(t, sp + 2 <= frameSize()); assert(t, sp - 4 >= localSize()); - uint8_t b4 = get(sp - 4); - uint8_t b3 = get(sp - 3); - uint8_t b2 = get(sp - 2); - uint8_t b1 = get(sp - 1); + ir::Type b4 = get(sp - 4); + ir::Type b3 = get(sp - 3); + ir::Type b2 = get(sp - 2); + ir::Type b1 = get(sp - 1); set(sp - 2, b4); set(sp - 1, b3); @@ -1618,7 +1617,7 @@ class Frame { void swapped() { assert(t, sp - 2 >= localSize()); - uint8_t saved = get(sp - 1); + ir::Type saved = get(sp - 1); set(sp - 1, get(sp - 2)); set(sp - 2, saved); @@ -1854,7 +1853,7 @@ class Frame { assert(t, sp >= 1); assert(t, sp - 1 >= localSize()); - if (get(sp - 1) == Object) { + if (get(sp - 1) == types.object) { storedObject(translateLocalIndex(context, 1, index)); } else { storedInt(translateLocalIndex(context, 1, index)); @@ -1883,7 +1882,7 @@ class Frame { void dupX2() { ir::Value* s0 = popQuiet(types.i4); - if (get(sp - 2) == Long) { + if (get(sp - 2) == types.i8) { ir::Value* s1 = popLongQuiet(); pushQuiet(types.i4, s0); @@ -1903,7 +1902,7 @@ class Frame { } void dup2() { - if (get(sp - 1) == Long) { + if (get(sp - 1) == types.i8) { pushLongQuiet(c->peek(2, 0)); } else { ir::Value* s0 = popQuiet(types.i4); @@ -1919,7 +1918,7 @@ class Frame { } void dup2X1() { - if (get(sp - 1) == Long) { + if (get(sp - 1) == types.i8) { ir::Value* s0 = popLongQuiet(); ir::Value* s1 = popQuiet(types.i4); @@ -1942,10 +1941,10 @@ class Frame { } void dup2X2() { - if (get(sp - 1) == Long) { + if (get(sp - 1) == types.i8) { ir::Value* s0 = popLongQuiet(); - if (get(sp - 3) == Long) { + if (get(sp - 3) == types.i8) { ir::Value* s1 = popLongQuiet(); pushLongQuiet(s0); @@ -2131,7 +2130,7 @@ class Frame { // Innermost subroutine we're compiling code for Subroutine* subroutine; - uint8_t* stackMap; + ir::Type* stackMap; unsigned ip; unsigned sp; unsigned level; @@ -3446,6 +3445,7 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) void handleEntrance(MyThread* t, Frame* frame) { + ir::Types types(TargetBytesPerWord); object method = frame->context->method; if ((methodFlags(t, method) & (ACC_SYNCHRONIZED | ACC_STATIC)) @@ -3458,7 +3458,7 @@ handleEntrance(MyThread* t, Frame* frame) frame->types.object, loadLocal(frame->context, 1, frame->types.object, 0), index); - frame->set(index, Frame::Object); + frame->set(index, types.object); } handleMonitorEvent @@ -4042,7 +4042,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Types types(TargetBytesPerWord); start: - uint8_t* stackMap = static_cast(stack.push(stackSize)); + ir::Type* stackMap + = static_cast(stack.push(stackSize * sizeof(ir::Type))); frame = new (stack.push(sizeof(Frame))) Frame(frame, stackMap); loop: @@ -4077,22 +4078,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (DebugInstructions) { unsigned startingIp = ip; - // TODO: fix stack printing fprintf(stderr, " stack: ["); for (size_t i = frame->localSize(); i < frame->sp; i++) { - switch (frame->get(i)) { - case Frame::Integer: + ir::Type ty = frame->get(i); + if (ty == types.i4) { fprintf(stderr, "I"); - break; - case Frame::Long: + } else if (ty == types.i8) { fprintf(stderr, "L"); - break; - case Frame::Object: + } else if (ty == types.f4) { + fprintf(stderr, "F"); + } else if (ty == types.f8) { + fprintf(stderr, "D"); + } else if (ty == types.object) { fprintf(stderr, "O"); - break; - default: + } else { fprintf(stderr, "?"); - break; } } fprintf(stderr, "]\n"); @@ -6117,7 +6117,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->dispose(); frame = 0; stack.pop(sizeof(Frame)); - stack.pop(stackSize); + stack.pop(stackSize * sizeof(ir::Type)); switch (stack.popValue()) { case Return: return; @@ -7022,13 +7022,13 @@ compile(MyThread* t, Context* context) c->init(codeLength(t, methodCode(t, context->method)), footprint, locals, alignedFrameSize(t, context->method)); - THREAD_RUNTIME_ARRAY(t, uint8_t, stackMap, - codeMaxStack(t, methodCode(t, context->method))); - Frame frame(context, RUNTIME_ARRAY_BODY(stackMap)); + ir::Type* stackMap = (ir::Type*)malloc( + sizeof(ir::Type) * codeMaxStack(t, methodCode(t, context->method))); + Frame frame(context, stackMap); unsigned index = methodParameterFootprint(t, context->method); if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { - frame.set(--index, Frame::Object); + frame.set(--index, frame.types.object); c->initLocal(index, frame.types.object); } @@ -7040,29 +7040,29 @@ compile(MyThread* t, Context* context) switch (*it.next()) { case 'L': case '[': - frame.set(--index, Frame::Object); + frame.set(--index, frame.types.object); c->initLocal(index, frame.types.object); break; case 'J': - frame.set(--index, Frame::Long); - frame.set(--index, Frame::Long); + frame.set(--index, frame.types.i8); + frame.set(--index, frame.types.i8); c->initLocal(index, frame.types.i8); break; case 'D': - frame.set(--index, Frame::Long); - frame.set(--index, Frame::Long); + frame.set(--index, frame.types.f8); + frame.set(--index, frame.types.f8); c->initLocal(index, frame.types.f8); break; case 'F': - frame.set(--index, Frame::Integer); + frame.set(--index, frame.types.i4); c->initLocal(index, frame.types.f4); break; default: - frame.set(--index, Frame::Integer); + frame.set(--index, frame.types.i4); c->initLocal(index, frame.types.i4); break; } @@ -7108,12 +7108,10 @@ compile(MyThread* t, Context* context) c->restoreState(state); - THREAD_RUNTIME_ARRAY( - t, - uint8_t, - stackMap, - codeMaxStack(t, methodCode(t, context->method))); - Frame frame2(&frame, RUNTIME_ARRAY_BODY(stackMap)); + ir::Type* stackMap = (ir::Type*)malloc( + sizeof(ir::Type) + * codeMaxStack(t, methodCode(t, context->method))); + Frame frame2(&frame, stackMap); unsigned end = duplicatedBaseIp + exceptionHandlerEnd(eh); if (exceptionHandlerIp(eh) >= static_cast(start) @@ -7128,7 +7126,7 @@ compile(MyThread* t, Context* context) for (unsigned i = 1; i < codeMaxStack(t, methodCode(t, context->method)); ++i) { - frame2.set(localSize(t, context->method) + i, Frame::Integer); + frame2.set(localSize(t, context->method) + i, frame2.types.i4); } compile(t, &frame2, exceptionHandlerIp(eh), start); @@ -7146,6 +7144,7 @@ compile(MyThread* t, Context* context) context->dirtyRoots = false; calculateFrameMaps(t, context, 0, 0, 0); } + free(stackMap); } void From 955f4918b4bb9bd58047a8765ee71f4c039f8f11 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Mon, 5 May 2014 15:21:48 -0600 Subject: [PATCH 82/89] parameterize many Frame:: methods by type --- src/compile.cpp | 1070 +++++++++++++++++++++++------------------------ 1 file changed, 522 insertions(+), 548 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 31fb1d74ce..dbcacf6eb9 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1465,22 +1465,6 @@ class Frame { return stackMap[si]; } - void pushedInt() { - assert(t, sp + 1 <= frameSize()); - set(sp++, types.i4); - } - - void pushedLong() { - assert(t, sp + 2 <= frameSize()); - set(sp++, types.i8); - set(sp++, types.i8); - } - - void pushedObject() { - assert(t, sp + 1 <= frameSize()); - set(sp++, types.object); - } - void popped(unsigned count) { assert(t, sp >= count); assert(t, sp - count >= localSize()); @@ -1489,28 +1473,6 @@ class Frame { -- count; } } - - void poppedInt() { - assert(t, sp >= 1); - assert(t, sp - 1 >= localSize()); - assert(t, get(sp - 1) == types.i4); - -- sp; - } - - void poppedLong() { - assert(t, sp >= 1); - assert(t, sp - 2 >= localSize()); - assert(t, get(sp - 1) == types.i8); - assert(t, get(sp - 2) == types.i8); - sp -= 2; - } - - void poppedObject() { - assert(t, sp >= 1); - assert(t, sp - 1 >= localSize()); - assert(t, get(sp - 1) == types.object); - set(--sp, types.i4); - } void storedInt(unsigned index) { assert(t, index < localSize()); @@ -1523,11 +1485,6 @@ class Frame { set(index + 1, types.i8); } - void storedObject(unsigned index) { - assert(t, index < localSize()); - set(index, types.object); - } - void dupped() { assert(t, sp + 1 <= frameSize()); assert(t, sp - 1 >= localSize()); @@ -1695,207 +1652,160 @@ class Frame { this->ip = bytecodeIp; } - void pushQuiet(ir::Type type, ir::Value* o) - { - c->push(type, o); - } + // void c->push(ir::Type type, ir::Value* o) + // { + // c->push(type, o); + // } - void pushLongQuiet(ir::Value* o) - { - pushQuiet(types.i8, o); - } + // void c->push(types.i8, ir::Value* o) + // { + // c->push(types.i8, o); + // } - ir::Value* popQuiet(ir::Type type) - { - return c->pop(type); - } + // ir::Value* c->pop(ir::Type type) + // { + // return c->pop(type); + // } - ir::Value* popLongQuiet() - { - return popQuiet(types.i8); - } + // ir::Value* c->pop(types.i8) + // { + // return c->pop(types.i8); + // } - void pushSmall(ir::Value* o) + void push(ir::Type type, ir::Value* o) { - pushQuiet(types.i4, o); - pushedInt(); - } - - void pushInt(ir::Value* o) - { - assert(t, o->type == types.i4); - pushSmall(o); - } - - void pushFloat(ir::Value* o) - { - assert(t, o->type == types.f4); - pushSmall(o); - } - - void pushAddress() - { - c->pushed(ir::Type(ir::Type::Address, TargetBytesPerWord)); - - pushedInt(); - } - - void pushObject(ir::Value* o) - { - assert(t, o->type == types.object || o->type.flavor() == ir::Type::Address); - pushQuiet(types.object, o); - pushedObject(); + assert(t, type == o->type); + c->push(o->type, o); + assert(t, sp + 1 <= frameSize()); + set(sp++, type); } void pushObject() { c->pushed(types.object); - pushedObject(); + assert(t, sp + 1 <= frameSize()); + set(sp++, types.object); } - void pushLarge(ir::Value* o) + void pushLarge(ir::Type type, ir::Value* o) { - pushLongQuiet(o); - pushedLong(); + assert(t, o->type == type); + c->push(type, o); + assert(t, sp + 2 <= frameSize()); + set(sp++, type); + set(sp++, type); } - void pushLong(ir::Value* o) - { - assert(t, o->type == types.i8); - pushLarge(o); - } + // void pushLarge(types.i8, ir::Value* o) + // { + // pushLarge(types.i8, o); + // } - void pushDouble(ir::Value* o) - { - assert(t, o->type == types.f8); - pushLarge(o); - } + // void pushLarge(types.f8, ir::Value* o) + // { + // pushLarge(types.f8, o); + // } void pop(unsigned count) { popped(count); c->popped(count); } - ir::Value* popInt() + ir::Value* pop(ir::Type type) { - poppedInt(); - return popQuiet(types.i4); + assert(t, sp >= 1); + assert(t, sp - 1 >= localSize()); + assert(t, get(sp - 1) == type); + set(--sp, types.i4); + return c->pop(type); } - ir::Value* popLong() + ir::Value* popLarge(ir::Type type) { - poppedLong(); - return popLongQuiet(); + assert(t, sp >= 1); + assert(t, sp - 2 >= localSize()); + assert(t, get(sp - 1) == type); + assert(t, get(sp - 2) == type); + sp -= 2; + return c->pop(type); } - ir::Value* popObject() - { - poppedObject(); - return popQuiet(types.object); - } - - void loadInt(unsigned index) { - assert(t, index < localSize()); - pushInt(loadLocal(context, 1, types.i4, index)); - } - - void loadFloat(unsigned index) + void load(ir::Type type, unsigned index) { assert(t, index < localSize()); - pushFloat(loadLocal(context, 1, types.f4, index)); + push(type, loadLocal(context, 1, type, index)); } void loadLong(unsigned index) { assert(t, index < static_cast(localSize() - 1)); - pushLong(loadLocal(context, 2, types.i8, index)); + pushLarge(types.i8, loadLocal(context, 2, types.i8, index)); } void loadDouble(unsigned index) { assert(t, index < static_cast(localSize() - 1)); - pushDouble(loadLocal(context, 2, types.f8, index)); + pushLarge(types.f8, loadLocal(context, 2, types.f8, index)); } void loadObject(unsigned index) { assert(t, index < localSize()); - pushObject(loadLocal(context, 1, types.object, index)); + push(types.object, loadLocal(context, 1, types.object, index)); } - void storeInt(unsigned index) { - storeLocal(context, 1, types.i4, popInt(), index); - storedInt(translateLocalIndex(context, 1, index)); - } - - void storeFloat(unsigned index) + void store(ir::Type type, unsigned index) { - storeLocal(context, 1, types.f4, popInt(), index); - storedInt(translateLocalIndex(context, 1, index)); + assert(t, type == types.i4 || type == types.f4 || type == types.object); + storeLocal(context, 1, type, pop(type), index); + unsigned ti = translateLocalIndex(context, 1, index); + assert(t, ti < localSize()); + set(ti, type); } void storeLong(unsigned index) { - storeLocal(context, 2, types.i8, popLong(), index); + storeLocal(context, 2, types.i8, popLarge(types.i8), index); storedLong(translateLocalIndex(context, 2, index)); } void storeDouble(unsigned index) { - storeLocal(context, 2, types.f8, popLong(), index); + storeLocal(context, 2, types.f8, popLarge(types.f8), index); storedLong(translateLocalIndex(context, 2, index)); } - void storeObject(unsigned index) { - storeLocal(context, 1, types.object, popObject(), index); - storedObject(translateLocalIndex(context, 1, index)); - } - - void storeObjectOrAddress(unsigned index) { - storeLocal(context, 1, types.object, popQuiet(types.object), index); - - assert(t, sp >= 1); - assert(t, sp - 1 >= localSize()); - if (get(sp - 1) == types.object) { - storedObject(translateLocalIndex(context, 1, index)); - } else { - storedInt(translateLocalIndex(context, 1, index)); - } - - popped(1); - } - void dup() { - pushQuiet(types.i4, c->peek(1, 0)); + c->push(types.i4, c->peek(1, 0)); dupped(); } void dupX1() { - ir::Value* s0 = popQuiet(types.i4); - ir::Value* s1 = popQuiet(types.i4); + ir::Value* s0 = c->pop(types.i4); + ir::Value* s1 = c->pop(types.i4); - pushQuiet(types.i4, s0); - pushQuiet(types.i4, s1); - pushQuiet(types.i4, s0); + c->push(types.i4, s0); + c->push(types.i4, s1); + c->push(types.i4, s0); duppedX1(); } void dupX2() { - ir::Value* s0 = popQuiet(types.i4); + ir::Value* s0 = c->pop(types.i4); if (get(sp - 2) == types.i8) { - ir::Value* s1 = popLongQuiet(); + ir::Value* s1 = c->pop(types.i8); - pushQuiet(types.i4, s0); - pushLongQuiet(s1); - pushQuiet(types.i4, s0); + c->push(types.i4, s0); + c->push(types.i8, s1); + c->push(types.i4, s0); } else { - ir::Value* s1 = popQuiet(types.i4); - ir::Value* s2 = popQuiet(types.i4); + ir::Value* s1 = c->pop(types.i4); + ir::Value* s2 = c->pop(types.i4); - pushQuiet(types.i4, s0); - pushQuiet(types.i4, s2); - pushQuiet(types.i4, s1); - pushQuiet(types.i4, s0); + c->push(types.i4, s0); + c->push(types.i4, s2); + c->push(types.i4, s1); + c->push(types.i4, s0); } duppedX2(); @@ -1903,15 +1813,15 @@ class Frame { void dup2() { if (get(sp - 1) == types.i8) { - pushLongQuiet(c->peek(2, 0)); + c->push(types.i8, c->peek(2, 0)); } else { - ir::Value* s0 = popQuiet(types.i4); - ir::Value* s1 = popQuiet(types.i4); + ir::Value* s0 = c->pop(types.i4); + ir::Value* s1 = c->pop(types.i4); - pushQuiet(types.i4, s1); - pushQuiet(types.i4, s0); - pushQuiet(types.i4, s1); - pushQuiet(types.i4, s0); + c->push(types.i4, s1); + c->push(types.i4, s0); + c->push(types.i4, s1); + c->push(types.i4, s0); } dupped2(); @@ -1919,22 +1829,22 @@ class Frame { void dup2X1() { if (get(sp - 1) == types.i8) { - ir::Value* s0 = popLongQuiet(); - ir::Value* s1 = popQuiet(types.i4); + ir::Value* s0 = c->pop(types.i8); + ir::Value* s1 = c->pop(types.i4); - pushLongQuiet(s0); - pushQuiet(types.i4, s1); - pushLongQuiet(s0); + c->push(types.i8, s0); + c->push(types.i4, s1); + c->push(types.i8, s0); } else { - ir::Value* s0 = popQuiet(types.i4); - ir::Value* s1 = popQuiet(types.i4); - ir::Value* s2 = popQuiet(types.i4); + ir::Value* s0 = c->pop(types.i4); + ir::Value* s1 = c->pop(types.i4); + ir::Value* s2 = c->pop(types.i4); - pushQuiet(types.i4, s1); - pushQuiet(types.i4, s0); - pushQuiet(types.i4, s2); - pushQuiet(types.i4, s1); - pushQuiet(types.i4, s0); + c->push(types.i4, s1); + c->push(types.i4, s0); + c->push(types.i4, s2); + c->push(types.i4, s1); + c->push(types.i4, s0); } dupped2X1(); @@ -1942,46 +1852,46 @@ class Frame { void dup2X2() { if (get(sp - 1) == types.i8) { - ir::Value* s0 = popLongQuiet(); + ir::Value* s0 = c->pop(types.i8); if (get(sp - 3) == types.i8) { - ir::Value* s1 = popLongQuiet(); + ir::Value* s1 = c->pop(types.i8); - pushLongQuiet(s0); - pushLongQuiet(s1); - pushLongQuiet(s0); + c->push(types.i8, s0); + c->push(types.i8, s1); + c->push(types.i8, s0); } else { - ir::Value* s1 = popQuiet(types.i4); - ir::Value* s2 = popQuiet(types.i4); + ir::Value* s1 = c->pop(types.i4); + ir::Value* s2 = c->pop(types.i4); - pushLongQuiet(s0); - pushQuiet(types.i4, s2); - pushQuiet(types.i4, s1); - pushLongQuiet(s0); + c->push(types.i8, s0); + c->push(types.i4, s2); + c->push(types.i4, s1); + c->push(types.i8, s0); } } else { - ir::Value* s0 = popQuiet(types.i4); - ir::Value* s1 = popQuiet(types.i4); - ir::Value* s2 = popQuiet(types.i4); - ir::Value* s3 = popQuiet(types.i4); + ir::Value* s0 = c->pop(types.i4); + ir::Value* s1 = c->pop(types.i4); + ir::Value* s2 = c->pop(types.i4); + ir::Value* s3 = c->pop(types.i4); - pushQuiet(types.i4, s1); - pushQuiet(types.i4, s0); - pushQuiet(types.i4, s3); - pushQuiet(types.i4, s2); - pushQuiet(types.i4, s1); - pushQuiet(types.i4, s0); + c->push(types.i4, s1); + c->push(types.i4, s0); + c->push(types.i4, s3); + c->push(types.i4, s2); + c->push(types.i4, s1); + c->push(types.i4, s0); } dupped2X2(); } void swap() { - ir::Value* s0 = popQuiet(types.i4); - ir::Value* s1 = popQuiet(types.i4); + ir::Value* s0 = c->pop(types.i4); + ir::Value* s1 = c->pop(types.i4); - pushQuiet(types.i4, s0); - pushQuiet(types.i4, s1); + c->push(types.i4, s0); + c->push(types.i4, s1); swapped(); } @@ -2014,17 +1924,17 @@ class Frame { case CharField: case ShortField: case IntField: - return pushInt(result); + return push(types.i4, result); case FloatField: - return pushFloat(result); + return push(types.f4, result); case ObjectField: - return pushObject(result); + return push(types.object, result); case LongField: - return pushLong(result); + return pushLarge(types.i8, result); case DoubleField: - return pushDouble(result); + return pushLarge(types.f8, result); default: abort(t); @@ -2089,7 +1999,7 @@ class Frame { // Push a dummy value to the stack, representing the return address (which // we don't need, since we're expanding everything statically). // TODO: in the future, push a value that we can track through type checking - pushObject(c->constant(0, types.object)); + push(types.object, c->constant(0, types.object)); if (DebugInstructions) { fprintf(stderr, "startSubroutine %u %u\n", ip, returnAddress); @@ -3193,21 +3103,24 @@ resultSize(MyThread* t, unsigned code) ir::Value* popField(MyThread* t, Frame* frame, int code) { + ir::Types types(TargetBytesPerWord); switch (code) { case ByteField: case BooleanField: case CharField: case ShortField: - case FloatField: case IntField: - return frame->popInt(); + return frame->pop(types.i4); + case FloatField: + return frame->pop(types.f4); - case DoubleField: case LongField: - return frame->popLong(); + return frame->popLarge(types.i8); + case DoubleField: + return frame->popLarge(types.f8); case ObjectField: - return frame->popObject(); + return frame->pop(types.object); default: abort(t); } @@ -3721,10 +3634,10 @@ bool floatBranch(MyThread* t, ir::Value* popLongAddress(Frame* frame) { ir::Types types(TargetBytesPerWord); - return TargetBytesPerWord == 8 ? frame->popLong() - : frame->c->load(ir::SignExtend, - frame->popLong(), - types.address); + return TargetBytesPerWord == 8 + ? frame->popLarge(types.i8) + : frame->c->load( + ir::SignExtend, frame->popLarge(types.i8), types.address); } bool @@ -3742,17 +3655,21 @@ intrinsic(MyThread* t, Frame* frame, object target) if (MATCH(methodName(t, target), "sqrt") and MATCH(methodSpec(t, target), "(D)D")) { - frame->pushDouble(c->unaryOp(lir::FloatSquareRoot, frame->popLong())); + frame->pushLarge( + types.f8, + c->unaryOp(lir::FloatSquareRoot, frame->popLarge(types.f8))); return true; } else if (MATCH(methodName(t, target), "abs")) { if (MATCH(methodSpec(t, target), "(I)I")) { - frame->pushInt(c->unaryOp(lir::Absolute, frame->popInt())); + frame->push(types.i4, c->unaryOp(lir::Absolute, frame->pop(types.i4))); return true; } else if (MATCH(methodSpec(t, target), "(J)J")) { - frame->pushLong(c->unaryOp(lir::Absolute, frame->popLong())); + frame->pushLarge(types.i8, + c->unaryOp(lir::Absolute, frame->popLarge(types.i8))); return true; } else if (MATCH(methodSpec(t, target), "(F)F")) { - frame->pushFloat(c->unaryOp(lir::FloatAbsolute, frame->popInt())); + frame->push(types.f4, + c->unaryOp(lir::FloatAbsolute, frame->pop(types.f4))); return true; } } @@ -3762,16 +3679,17 @@ intrinsic(MyThread* t, Frame* frame, object target) and MATCH(methodSpec(t, target), "(J)B")) { ir::Value* address = popLongAddress(frame); - frame->popObject(); - frame->pushInt(c->load( - ir::SignExtend, c->memory(address, types.i1), types.i4)); + frame->pop(types.object); + frame->push( + types.i4, + c->load(ir::SignExtend, c->memory(address, types.i1), types.i4)); return true; } else if (MATCH(methodName(t, target), "putByte") and MATCH(methodSpec(t, target), "(JB)V")) { - ir::Value* value = frame->popInt(); + ir::Value* value = frame->pop(types.i4); ir::Value* address = popLongAddress(frame); - frame->popObject(); + frame->pop(types.object); c->store(value, c->memory(address, types.i1)); return true; } else if ((MATCH(methodName(t, target), "getShort") @@ -3780,18 +3698,19 @@ intrinsic(MyThread* t, Frame* frame, object target) and MATCH(methodSpec(t, target), "(J)C"))) { ir::Value* address = popLongAddress(frame); - frame->popObject(); - frame->pushInt(c->load( - ir::SignExtend, c->memory(address, types.i2), types.i4)); + frame->pop(types.object); + frame->push( + types.i4, + c->load(ir::SignExtend, c->memory(address, types.i2), types.i4)); return true; } else if ((MATCH(methodName(t, target), "putShort") and MATCH(methodSpec(t, target), "(JS)V")) or (MATCH(methodName(t, target), "putChar") and MATCH(methodSpec(t, target), "(JC)V"))) { - ir::Value* value = frame->popInt(); + ir::Value* value = frame->pop(types.i4); ir::Value* address = popLongAddress(frame); - frame->popObject(); + frame->pop(types.object); c->store(value, c->memory(address, types.i2)); return true; } else if ((MATCH(methodName(t, target), "getInt") @@ -3800,22 +3719,22 @@ intrinsic(MyThread* t, Frame* frame, object target) and MATCH(methodSpec(t, target), "(J)F"))) { ir::Value* address = popLongAddress(frame); - frame->popObject(); + frame->pop(types.object); ir::Type type = MATCH(methodName(t, target), "getInt") ? types.i4 : types.f4; - frame->pushSmall( - c->load(ir::SignExtend, c->memory(address, type), type)); + frame->push(type, + c->load(ir::SignExtend, c->memory(address, type), type)); return true; } else if ((MATCH(methodName(t, target), "putInt") and MATCH(methodSpec(t, target), "(JI)V")) or (MATCH(methodName(t, target), "putFloat") and MATCH(methodSpec(t, target), "(JF)V"))) { - ir::Value* value = frame->popInt(); - ir::Value* address = popLongAddress(frame); - frame->popObject(); ir::Type type = MATCH(methodName(t, target), "putInt") ? types.i4 : types.f4; + ir::Value* value = frame->pop(type); + ir::Value* address = popLongAddress(frame); + frame->pop(types.object); c->store(value, c->memory(address, type)); return true; } else if ((MATCH(methodName(t, target), "getLong") @@ -3824,39 +3743,39 @@ intrinsic(MyThread* t, Frame* frame, object target) and MATCH(methodSpec(t, target), "(J)D"))) { ir::Value* address = popLongAddress(frame); - frame->popObject(); + frame->pop(types.object); ir::Type type = MATCH(methodName(t, target), "getLong") ? types.i8 : types.f8; - frame->pushLarge( - c->load(ir::SignExtend, c->memory(address, type), type)); + frame->pushLarge(type, + c->load(ir::SignExtend, c->memory(address, type), type)); return true; } else if ((MATCH(methodName(t, target), "putLong") and MATCH(methodSpec(t, target), "(JJ)V")) or (MATCH(methodName(t, target), "putDouble") and MATCH(methodSpec(t, target), "(JD)V"))) { - ir::Value* value = frame->popLong(); - ir::Value* address = popLongAddress(frame); - frame->popObject(); ir::Type type = MATCH(methodName(t, target), "putLong") ? types.i8 : types.f8; + ir::Value* value = frame->popLarge(type); + ir::Value* address = popLongAddress(frame); + frame->pop(types.object); c->store(value, c->memory(address, type)); return true; } else if (MATCH(methodName(t, target), "getAddress") and MATCH(methodSpec(t, target), "(J)J")) { ir::Value* address = popLongAddress(frame); - frame->popObject(); - frame->pushLong(c->load(ir::SignExtend, - c->memory(address, types.address), - types.i8)); + frame->pop(types.object); + frame->pushLarge( + types.i8, + c->load(ir::SignExtend, c->memory(address, types.address), types.i8)); return true; } else if (MATCH(methodName(t, target), "putAddress") and MATCH(methodSpec(t, target), "(JJ)V")) { - ir::Value* value = frame->popLong(); + ir::Value* value = frame->popLarge(types.i8); ir::Value* address = popLongAddress(frame); - frame->popObject(); + frame->pop(types.object); c->store(value, c->memory(address, types.address)); return true; } @@ -4112,8 +4031,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case iaload: case laload: case saload: { - ir::Value* index = frame->popInt(); - ir::Value* array = frame->popObject(); + ir::Value* index = frame->pop(types.i4); + ir::Value* array = frame->pop(types.object); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); @@ -4126,59 +4045,62 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (instruction) { case aaload: - frame->pushObject( + frame->push( + types.object, c->load(ir::SignExtend, c->memory(array, types.object, TargetArrayBody, index), types.object)); break; case faload: - frame->pushFloat( - c->load(ir::SignExtend, - c->memory(array, types.f4, TargetArrayBody, index), - types.f4)); + frame->push(types.f4, + c->load(ir::SignExtend, + c->memory(array, types.f4, TargetArrayBody, index), + types.f4)); break; case iaload: - frame->pushInt( - c->load(ir::SignExtend, - c->memory(array, types.i4, TargetArrayBody, index), - types.i4)); + frame->push(types.i4, + c->load(ir::SignExtend, + c->memory(array, types.i4, TargetArrayBody, index), + types.i4)); break; case baload: - frame->pushInt( - c->load(ir::SignExtend, - c->memory(array, types.i1, TargetArrayBody, index), - types.i4)); + frame->push(types.i4, + c->load(ir::SignExtend, + c->memory(array, types.i1, TargetArrayBody, index), + types.i4)); break; case caload: - frame->pushInt( - c->load(ir::ZeroExtend, - c->memory(array, types.i2, TargetArrayBody, index), - types.i4)); + frame->push(types.i4, + c->load(ir::ZeroExtend, + c->memory(array, types.i2, TargetArrayBody, index), + types.i4)); break; case daload: - frame->pushDouble( + frame->pushLarge( + types.f8, c->load(ir::SignExtend, c->memory(array, types.f8, TargetArrayBody, index), types.f8)); break; case laload: - frame->pushLong( + frame->pushLarge( + types.i8, c->load(ir::SignExtend, c->memory(array, types.i8, TargetArrayBody, index), types.i8)); break; case saload: - frame->pushInt( - c->load(ir::SignExtend, - c->memory(array, types.i2, TargetArrayBody, index), - types.i4)); + frame->push(types.i4, + c->load(ir::SignExtend, + c->memory(array, types.i2, TargetArrayBody, index), + types.i4)); break; } } break; @@ -4192,16 +4114,20 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lastore: case sastore: { ir::Value* value; - if (instruction == dastore or instruction == lastore) { - value = frame->popLong(); + if (instruction == lastore) { + value = frame->popLarge(types.i8); + } else if (instruction == dastore) { + value = frame->popLarge(types.f8); } else if (instruction == aastore) { - value = frame->popObject(); + value = frame->pop(types.object); + } else if (instruction == fastore) { + value = frame->pop(types.f4); } else { - value = frame->popInt(); + value = frame->pop(types.i4); } - ir::Value* index = frame->popInt(); - ir::Value* array = frame->popObject(); + ir::Value* index = frame->pop(types.i4); + ir::Value* array = frame->pop(types.object); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); @@ -4260,7 +4186,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case aconst_null: - frame->pushObject(c->constant(0, types.object)); + frame->push(types.object, c->constant(0, types.object)); break; case aload: @@ -4293,7 +4219,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, object class_ = resolveClassInPool(t, context->method, index - 1, false); - ir::Value* length = frame->popInt(); + ir::Value* length = frame->pop(types.i4); object argument; Thunk thunk; @@ -4305,50 +4231,53 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, thunk = makeBlankObjectArrayFromReferenceThunk; } - frame->pushObject(c->call(c->constant(getThunk(t, thunk), types.address), - 0, - frame->trace(0, 0), - types.object, - 3, - c->threadRegister(), - frame->append(argument), - length)); + frame->push(types.object, + c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + types.object, + 3, + c->threadRegister(), + frame->append(argument), + length)); } break; case areturn: { handleExit(t, frame); - c->return_(frame->popObject()); + c->return_(frame->pop(types.object)); } goto next; case arraylength: { - frame->pushInt(c->load( - ir::SignExtend, - c->memory(frame->popObject(), types.address, TargetArrayLength), - types.i4)); + frame->push(types.i4, + c->load(ir::SignExtend, + c->memory(frame->pop(types.object), + types.address, + TargetArrayLength), + types.i4)); } break; case astore: - frame->storeObjectOrAddress(codeBody(t, code, ip++)); + frame->store(types.object, codeBody(t, code, ip++)); break; case astore_0: - frame->storeObjectOrAddress(0); + frame->store(types.object, 0); break; case astore_1: - frame->storeObjectOrAddress(1); + frame->store(types.object, 1); break; case astore_2: - frame->storeObjectOrAddress(2); + frame->store(types.object, 2); break; case astore_3: - frame->storeObjectOrAddress(3); + frame->store(types.object, 3); break; case athrow: { - ir::Value* target = frame->popObject(); + ir::Value* target = frame->pop(types.object); c->call(c->constant(getThunk(t, throw_Thunk), types.address), Compiler::NoReturn, frame->trace(0, 0), @@ -4361,7 +4290,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto next; case bipush: - frame->pushInt( + frame->push( + types.i4, c->constant(static_cast(codeBody(t, code, ip++)), types.i4)); break; @@ -4398,15 +4328,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case d2f: { - frame->pushFloat(c->f2f(types.f4, frame->popLong())); + frame->push(types.f4, c->f2f(types.f4, frame->popLarge(types.f8))); } break; case d2i: { - frame->pushInt(c->f2i(types.i4, frame->popLong())); + frame->push(types.i4, c->f2i(types.i4, frame->popLarge(types.f8))); } break; case d2l: { - frame->pushLong(c->f2i(types.i8, frame->popLong())); + frame->pushLarge(types.i8, c->f2i(types.i8, frame->popLarge(types.f8))); } break; case dadd: @@ -4414,63 +4344,67 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case dmul: case ddiv: case vm::drem: { - ir::Value* a = frame->popLong(); - ir::Value* b = frame->popLong(); + ir::Value* a = frame->popLarge(types.f8); + ir::Value* b = frame->popLarge(types.f8); - frame->pushDouble( + frame->pushLarge( + types.f8, c->binaryOp(toCompilerBinaryOp(t, instruction), types.f8, a, b)); } break; case dcmpg: { - ir::Value* a = frame->popLong(); - ir::Value* b = frame->popLong(); + ir::Value* a = frame->popLarge(types.f8); + ir::Value* b = frame->popLarge(types.f8); if (floatBranch(t, frame, code, ip, false, a, b, &newIp)) { goto branch; } else { - frame->pushInt(c->call( - c->constant(getThunk(t, compareDoublesGThunk), types.address), - 0, - 0, - types.i4, - 4, - static_cast(0), - a, - static_cast(0), - b)); + frame->push(types.i4, + c->call(c->constant(getThunk(t, compareDoublesGThunk), + types.address), + 0, + 0, + types.i4, + 4, + static_cast(0), + a, + static_cast(0), + b)); } } break; case dcmpl: { - ir::Value* a = frame->popLong(); - ir::Value* b = frame->popLong(); + ir::Value* a = frame->popLarge(types.f8); + ir::Value* b = frame->popLarge(types.f8); if (floatBranch(t, frame, code, ip, true, a, b, &newIp)) { goto branch; } else { - frame->pushInt(c->call( - c->constant(getThunk(t, compareDoublesLThunk), types.address), - 0, - 0, - types.i4, - 4, - static_cast(0), - a, - static_cast(0), - b)); + frame->push(types.i4, + c->call(c->constant(getThunk(t, compareDoublesLThunk), + types.address), + 0, + 0, + types.i4, + 4, + static_cast(0), + a, + static_cast(0), + b)); } } break; case dconst_0: - frame->pushDouble(c->constant(doubleToBits(0.0), types.f8)); + frame->pushLarge(types.f8, c->constant(doubleToBits(0.0), types.f8)); break; - + case dconst_1: - frame->pushDouble(c->constant(doubleToBits(1.0), types.f8)); + frame->pushLarge(types.f8, c->constant(doubleToBits(1.0), types.f8)); break; case dneg: { - frame->pushDouble(c->unaryOp(lir::FloatNegate, frame->popLong())); + frame->pushLarge(types.f8, + c->unaryOp(lir::FloatNegate, frame->popLarge(types.f8))); } break; case dup: @@ -4498,15 +4432,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case f2d: { - frame->pushDouble(c->f2f(types.f8, frame->popInt())); + frame->pushLarge(types.f8, c->f2f(types.f8, frame->pop(types.f4))); } break; case f2i: { - frame->pushInt(c->f2i(types.i4, frame->popInt())); + frame->push(types.i4, c->f2i(types.i4, frame->pop(types.f4))); } break; case f2l: { - frame->pushLong(c->f2i(types.i8, frame->popInt())); + frame->pushLarge(types.i8, c->f2i(types.i8, frame->pop(types.f4))); } break; case fadd: @@ -4514,63 +4448,66 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case fmul: case fdiv: case frem: { - ir::Value* a = frame->popInt(); - ir::Value* b = frame->popInt(); + ir::Value* a = frame->pop(types.f4); + ir::Value* b = frame->pop(types.f4); - frame->pushFloat( + frame->push( + types.f4, c->binaryOp(toCompilerBinaryOp(t, instruction), types.f4, a, b)); } break; case fcmpg: { - ir::Value* a = frame->popInt(); - ir::Value* b = frame->popInt(); + ir::Value* a = frame->pop(types.f4); + ir::Value* b = frame->pop(types.f4); if (floatBranch(t, frame, code, ip, false, a, b, &newIp)) { goto branch; } else { - frame->pushInt(c->call( - c->constant(getThunk(t, compareFloatsGThunk), types.address), - 0, - 0, - types.i4, - 2, - a, - b)); + frame->push(types.i4, + c->call(c->constant(getThunk(t, compareFloatsGThunk), + types.address), + 0, + 0, + types.i4, + 2, + a, + b)); } } break; case fcmpl: { - ir::Value* a = frame->popInt(); - ir::Value* b = frame->popInt(); + ir::Value* a = frame->pop(types.f4); + ir::Value* b = frame->pop(types.f4); if (floatBranch(t, frame, code, ip, true, a, b, &newIp)) { goto branch; } else { - frame->pushInt(c->call( - c->constant(getThunk(t, compareFloatsLThunk), types.address), - 0, - 0, - types.i4, - 2, - a, - b)); + frame->push(types.i4, + c->call(c->constant(getThunk(t, compareFloatsLThunk), + types.address), + 0, + 0, + types.i4, + 2, + a, + b)); } } break; case fconst_0: - frame->pushFloat(c->constant(floatToBits(0.0), types.f4)); + frame->push(types.f4, c->constant(floatToBits(0.0), types.f4)); break; case fconst_1: - frame->pushFloat(c->constant(floatToBits(1.0), types.f4)); + frame->push(types.f4, c->constant(floatToBits(1.0), types.f4)); break; case fconst_2: - frame->pushFloat(c->constant(floatToBits(2.0), types.f4)); + frame->push(types.f4, c->constant(floatToBits(2.0), types.f4)); break; case fneg: { - frame->pushFloat(c->unaryOp(lir::FloatNegate, frame->popInt())); + frame->push(types.f4, c->unaryOp(lir::FloatNegate, frame->pop(types.f4))); } break; case getfield: @@ -4623,7 +4560,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } else { checkField(t, field, false); - table = frame->popObject(); + table = frame->pop(types.object); if (inTryBlock(t, code, ip - 3)) { c->saveLocals(); @@ -4634,59 +4571,75 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (fieldCode(t, field)) { case ByteField: case BooleanField: - frame->pushInt(c->load( - ir::SignExtend, - c->memory(table, types.i1, targetFieldOffset(context, field)), - types.i4)); + frame->push( + types.i4, + c->load( + ir::SignExtend, + c->memory(table, types.i1, targetFieldOffset(context, field)), + types.i4)); break; case CharField: - frame->pushInt(c->load( - ir::ZeroExtend, - c->memory(table, types.i2, targetFieldOffset(context, field)), - types.i4)); + frame->push( + types.i4, + c->load( + ir::ZeroExtend, + c->memory(table, types.i2, targetFieldOffset(context, field)), + types.i4)); break; case ShortField: - frame->pushInt(c->load( - ir::SignExtend, - c->memory(table, types.i2, targetFieldOffset(context, field)), - types.i4)); + frame->push( + types.i4, + c->load( + ir::SignExtend, + c->memory(table, types.i2, targetFieldOffset(context, field)), + types.i4)); break; case FloatField: - frame->pushFloat(c->load( - ir::SignExtend, - c->memory(table, types.f4, targetFieldOffset(context, field)), - types.f4)); + frame->push( + types.f4, + c->load( + ir::SignExtend, + c->memory(table, types.f4, targetFieldOffset(context, field)), + types.f4)); break; case IntField: - frame->pushInt(c->load( - ir::SignExtend, - c->memory(table, types.i4, targetFieldOffset(context, field)), - types.i4)); + frame->push( + types.i4, + c->load( + ir::SignExtend, + c->memory(table, types.i4, targetFieldOffset(context, field)), + types.i4)); break; case DoubleField: - frame->pushDouble(c->load( - ir::SignExtend, - c->memory(table, types.f8, targetFieldOffset(context, field)), - types.f8)); + frame->pushLarge( + types.f8, + c->load( + ir::SignExtend, + c->memory(table, types.f8, targetFieldOffset(context, field)), + types.f8)); break; case LongField: - frame->pushLong(c->load( - ir::SignExtend, - c->memory(table, types.i8, targetFieldOffset(context, field)), - types.i8)); + frame->pushLarge( + types.i8, + c->load( + ir::SignExtend, + c->memory(table, types.i8, targetFieldOffset(context, field)), + types.i8)); break; case ObjectField: - frame->pushObject(c->load( - ir::SignExtend, - c->memory(table, types.object, targetFieldOffset(context, field)), - types.object)); + frame->push(types.object, + c->load(ir::SignExtend, + c->memory(table, + types.object, + targetFieldOffset(context, field)), + types.object)); break; default: @@ -4730,7 +4683,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->threadRegister(), frame->append(pair)); } else { - ir::Value* instance = frame->popObject(); + ir::Value* instance = frame->pop(types.object); result = c->call( c->constant(getThunk(t, getFieldValueFromReferenceThunk), @@ -4775,31 +4728,39 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2b: { - frame->pushInt(c->truncateThenExtend( - ir::SignExtend, types.i4, types.i1, frame->popInt())); + frame->push( + types.i4, + c->truncateThenExtend( + ir::SignExtend, types.i4, types.i1, frame->pop(types.i4))); } break; case i2c: { - frame->pushInt(c->truncateThenExtend( - ir::ZeroExtend, types.i4, types.i2, frame->popInt())); + frame->push( + types.i4, + c->truncateThenExtend( + ir::ZeroExtend, types.i4, types.i2, frame->pop(types.i4))); } break; case i2d: { - frame->pushDouble(c->i2f(types.f8, frame->popInt())); + frame->pushLarge(types.f8, c->i2f(types.f8, frame->pop(types.i4))); } break; case i2f: { - frame->pushFloat(c->i2f(types.f4, frame->popInt())); + frame->push(types.f4, c->i2f(types.f4, frame->pop(types.i4))); } break; case i2l: - frame->pushLong(c->truncateThenExtend( - ir::SignExtend, types.i8, types.i4, frame->popInt())); + frame->pushLarge( + types.i8, + c->truncateThenExtend( + ir::SignExtend, types.i8, types.i4, frame->pop(types.i4))); break; case i2s: { - frame->pushInt(c->truncateThenExtend( - ir::SignExtend, types.i4, types.i2, frame->popInt())); + frame->push( + types.i4, + c->truncateThenExtend( + ir::SignExtend, types.i4, types.i2, frame->pop(types.i4))); } break; case iadd: @@ -4811,50 +4772,51 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case isub: case ixor: case imul: { - ir::Value* a = frame->popInt(); - ir::Value* b = frame->popInt(); - frame->pushInt( + ir::Value* a = frame->pop(types.i4); + ir::Value* b = frame->pop(types.i4); + frame->push( + types.i4, c->binaryOp(toCompilerBinaryOp(t, instruction), types.i4, a, b)); } break; case iconst_m1: - frame->pushInt(c->constant(-1, types.i4)); + frame->push(types.i4, c->constant(-1, types.i4)); break; case iconst_0: - frame->pushInt(c->constant(0, types.i4)); + frame->push(types.i4, c->constant(0, types.i4)); break; case iconst_1: - frame->pushInt(c->constant(1, types.i4)); + frame->push(types.i4, c->constant(1, types.i4)); break; case iconst_2: - frame->pushInt(c->constant(2, types.i4)); + frame->push(types.i4, c->constant(2, types.i4)); break; case iconst_3: - frame->pushInt(c->constant(3, types.i4)); + frame->push(types.i4, c->constant(3, types.i4)); break; case iconst_4: - frame->pushInt(c->constant(4, types.i4)); + frame->push(types.i4, c->constant(4, types.i4)); break; case iconst_5: - frame->pushInt(c->constant(5, types.i4)); + frame->push(types.i4, c->constant(5, types.i4)); break; case idiv: { - ir::Value* a = frame->popInt(); - ir::Value* b = frame->popInt(); + ir::Value* a = frame->pop(types.i4); + ir::Value* b = frame->pop(types.i4); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); frame->trace(0, 0); } - frame->pushInt(c->binaryOp(lir::Divide, types.i4, a, b)); + frame->push(types.i4, c->binaryOp(lir::Divide, types.i4, a, b)); } break; case if_acmpeq: @@ -4867,8 +4829,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - ir::Value* a = frame->popObject(); - ir::Value* b = frame->popObject(); + ir::Value* a = frame->pop(types.object); + ir::Value* b = frame->pop(types.object); ir::Value* target = frame->machineIpValue(newIp); c->condJump(toCompilerJumpOp(t, instruction), a, b, target); @@ -4888,8 +4850,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - ir::Value* a = frame->popInt(); - ir::Value* b = frame->popInt(); + ir::Value* a = frame->pop(types.i4); + ir::Value* b = frame->pop(types.i4); ir::Value* target = frame->machineIpValue(newIp); c->condJump(toCompilerJumpOp(t, instruction), a, b, target); @@ -4912,7 +4874,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } ir::Value* a = c->constant(0, types.i4); - ir::Value* b = frame->popInt(); + ir::Value* b = frame->pop(types.i4); c->condJump(toCompilerJumpOp(t, instruction), a, b, target); } goto branch; @@ -4928,7 +4890,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } ir::Value* a = c->constant(0, types.object); - ir::Value* b = frame->popObject(); + ir::Value* b = frame->pop(types.object); ir::Value* target = frame->machineIpValue(newIp); c->condJump(toCompilerJumpOp(t, instruction), a, b, target); @@ -4949,42 +4911,42 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case iload: - frame->loadInt(codeBody(t, code, ip++)); + frame->load(types.i4, codeBody(t, code, ip++)); break; case fload: - frame->loadFloat(codeBody(t, code, ip++)); + frame->load(types.f4, codeBody(t, code, ip++)); break; case iload_0: - frame->loadInt(0); + frame->load(types.i4, 0); break; case fload_0: - frame->loadFloat(0); + frame->load(types.f4, 0); break; case iload_1: - frame->loadInt(1); + frame->load(types.i4, 1); break; case fload_1: - frame->loadFloat(1); + frame->load(types.f4, 1); break; case iload_2: - frame->loadInt(2); + frame->load(types.i4, 2); break; case fload_2: - frame->loadFloat(2); + frame->load(types.f4, 2); break; case iload_3: - frame->loadInt(3); + frame->load(types.i4, 3); break; case fload_3: - frame->loadFloat(3); + frame->load(types.f4, 3); break; case ineg: { - frame->pushInt(c->unaryOp(lir::Negate, frame->popInt())); + frame->push(types.i4, c->unaryOp(lir::Negate, frame->pop(types.i4))); } break; case instanceof: { @@ -4997,7 +4959,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, object class_ = resolveClassInPool(t, context->method, index - 1, false); - ir::Value* instance = frame->popObject(); + ir::Value* instance = frame->pop(types.object); object argument; Thunk thunk; @@ -5009,14 +4971,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, thunk = instanceOfFromReferenceThunk; } - frame->pushInt(c->call(c->constant(getThunk(t, thunk), types.address), - 0, - frame->trace(0, 0), - types.i4, - 3, - c->threadRegister(), - frame->append(argument), - instance)); + frame->push(types.i4, + c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + types.i4, + 3, + c->threadRegister(), + frame->append(argument), + instance)); } break; case invokeinterface: { @@ -5210,61 +5173,61 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case irem: { - ir::Value* a = frame->popInt(); - ir::Value* b = frame->popInt(); + ir::Value* a = frame->pop(types.i4); + ir::Value* b = frame->pop(types.i4); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); frame->trace(0, 0); } - frame->pushInt(c->binaryOp(lir::Remainder, types.i4, a, b)); + frame->push(types.i4, c->binaryOp(lir::Remainder, types.i4, a, b)); } break; case ireturn: { handleExit(t, frame); - c->return_(frame->popInt()); + c->return_(frame->pop(types.i4)); } goto next; case freturn: { handleExit(t, frame); - c->return_(frame->popInt()); + c->return_(frame->pop(types.f4)); } goto next; case istore: - frame->storeInt(codeBody(t, code, ip++)); + frame->store(types.i4, codeBody(t, code, ip++)); break; case fstore: - frame->storeFloat(codeBody(t, code, ip++)); + frame->store(types.f4, codeBody(t, code, ip++)); break; case istore_0: - frame->storeInt(0); + frame->store(types.i4, 0); break; case fstore_0: - frame->storeFloat(0); + frame->store(types.f4, 0); break; case istore_1: - frame->storeInt(1); + frame->store(types.i4, 1); break; case fstore_1: - frame->storeFloat(1); + frame->store(types.f4, 1); break; case istore_2: - frame->storeInt(2); + frame->store(types.i4, 2); break; case fstore_2: - frame->storeFloat(2); + frame->store(types.f4, 2); break; case istore_3: - frame->storeInt(3); + frame->store(types.i4, 3); break; case fstore_3: - frame->storeFloat(3); + frame->store(types.f4, 3); break; case jsr: @@ -5291,15 +5254,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case l2d: { - frame->pushDouble(c->i2f(types.f8, frame->popLong())); + frame->pushLarge(types.f8, c->i2f(types.f8, frame->popLarge(types.i8))); } break; case l2f: { - frame->pushFloat(c->i2f(types.f4, frame->popLong())); + frame->push(types.f4, c->i2f(types.f4, frame->popLarge(types.i8))); } break; case l2i: - frame->pushInt(c->truncate(types.i4, frame->popLong())); + frame->push(types.i4, c->truncate(types.i4, frame->popLarge(types.i8))); break; case ladd: @@ -5308,20 +5271,22 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lsub: case lxor: case lmul: { - ir::Value* a = frame->popLong(); - ir::Value* b = frame->popLong(); - frame->pushLong( + ir::Value* a = frame->popLarge(types.i8); + ir::Value* b = frame->popLarge(types.i8); + frame->pushLarge( + types.i8, c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b)); } break; case lcmp: { - ir::Value* a = frame->popLong(); - ir::Value* b = frame->popLong(); + ir::Value* a = frame->popLarge(types.i8); + ir::Value* b = frame->popLarge(types.i8); if (integerBranch(t, frame, code, ip, a, b, &newIp)) { goto branch; } else { - frame->pushInt( + frame->push( + types.i4, c->call(c->constant(getThunk(t, compareLongsThunk), types.address), 0, 0, @@ -5335,11 +5300,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lconst_0: - frame->pushLong(c->constant(0, types.i8)); + frame->pushLarge(types.i8, c->constant(0, types.i8)); break; case lconst_1: - frame->pushLong(c->constant(1, types.i8)); + frame->pushLarge(types.i8, c->constant(1, types.i8)); break; case ldc: @@ -5366,37 +5331,41 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, v = resolveClassInPool(t, context->method, index - 1, false); if (UNLIKELY(v == 0)) { - frame->pushObject(c->call( - c->constant(getThunk(t, getJClassFromReferenceThunk), - types.address), - 0, - frame->trace(0, 0), + frame->push( types.object, - 2, - c->threadRegister(), - frame->append(makePair(t, context->method, reference)))); + c->call( + c->constant(getThunk(t, getJClassFromReferenceThunk), + types.address), + 0, + frame->trace(0, 0), + types.object, + 2, + c->threadRegister(), + frame->append(makePair(t, context->method, reference)))); } } if (v) { if (objectClass(t, v) == type(t, Machine::ClassType)) { - frame->pushObject(c->call( - c->constant(getThunk(t, getJClass64Thunk), types.address), - 0, - frame->trace(0, 0), - types.object, - 2, - c->threadRegister(), - frame->append(v))); + frame->push(types.object, + c->call(c->constant(getThunk(t, getJClass64Thunk), + types.address), + 0, + frame->trace(0, 0), + types.object, + 2, + c->threadRegister(), + frame->append(v))); } else { - frame->pushObject(frame->append(v)); + frame->push(types.object, frame->append(v)); } } } else { - frame->pushSmall(c->constant( - singletonValue(t, pool, index - 1), - singletonBit(t, pool, poolSize(t, pool), index - 1) ? types.f4 - : types.i4)); + ir::Type type = singletonBit(t, pool, poolSize(t, pool), index - 1) + ? types.f4 + : types.i4; + frame->push(type, + c->constant(singletonValue(t, pool, index - 1), type)); } } break; @@ -5407,22 +5376,22 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint64_t v; memcpy(&v, &singletonValue(t, pool, index - 1), 8); - frame->pushLarge(c->constant( - v, - singletonBit(t, pool, poolSize(t, pool), index - 1) ? types.f8 - : types.i8)); + ir::Type type = singletonBit(t, pool, poolSize(t, pool), index - 1) + ? types.f8 + : types.i8; + frame->pushLarge(type, c->constant(v, type)); } break; case ldiv_: { - ir::Value* a = frame->popLong(); - ir::Value* b = frame->popLong(); + ir::Value* a = frame->popLarge(types.i8); + ir::Value* b = frame->popLarge(types.i8); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); frame->trace(0, 0); } - frame->pushLong(c->binaryOp(lir::Divide, types.i8, a, b)); + frame->pushLarge(types.i8, c->binaryOp(lir::Divide, types.i8, a, b)); } break; case lload: @@ -5461,7 +5430,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case lneg: - frame->pushLong(c->unaryOp(lir::Negate, frame->popLong())); + frame->pushLarge(types.i8, + c->unaryOp(lir::Negate, frame->popLarge(types.i8))); break; case lookupswitch: { @@ -5469,7 +5439,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ip = (ip + 3) & ~3; // pad to four byte boundary - ir::Value* key = frame->popInt(); + ir::Value* key = frame->pop(types.i4); uint32_t defaultIp = base + codeReadInt32(t, code, ip); assert(t, defaultIp < codeLength(t, code)); @@ -5531,34 +5501,35 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lrem: { - ir::Value* a = frame->popLong(); - ir::Value* b = frame->popLong(); + ir::Value* a = frame->popLarge(types.i8); + ir::Value* b = frame->popLarge(types.i8); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); frame->trace(0, 0); } - frame->pushLong(c->binaryOp(lir::Remainder, types.i8, a, b)); + frame->pushLarge(types.i8, c->binaryOp(lir::Remainder, types.i8, a, b)); } break; case lreturn: { handleExit(t, frame); - c->return_(frame->popLong()); + c->return_(frame->popLarge(types.i8)); } goto next; case dreturn: { handleExit(t, frame); - c->return_(frame->popLong()); + c->return_(frame->popLarge(types.f8)); } goto next; case lshl: case lshr: case lushr: { - ir::Value* a = frame->popInt(); - ir::Value* b = frame->popLong(); - frame->pushLong( + ir::Value* a = frame->pop(types.i4); + ir::Value* b = frame->popLarge(types.i8); + frame->pushLarge( + types.i8, c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b)); } break; @@ -5598,7 +5569,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case monitorenter: { - ir::Value* target = frame->popObject(); + ir::Value* target = frame->pop(types.object); c->call( c->constant(getThunk(t, acquireMonitorForObjectThunk), types.address), 0, @@ -5610,7 +5581,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case monitorexit: { - ir::Value* target = frame->popObject(); + ir::Value* target = frame->pop(types.object); c->call( c->constant(getThunk(t, releaseMonitorForObjectThunk), types.address), 0, @@ -5659,7 +5630,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->constant(offset, types.i4)); frame->pop(dimensions); - frame->pushObject(result); + frame->push(types.object, result); } break; case new_: { @@ -5686,21 +5657,23 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, thunk = makeNewFromReferenceThunk; } - frame->pushObject(c->call(c->constant(getThunk(t, thunk), types.address), - 0, - frame->trace(0, 0), - types.object, - 2, - c->threadRegister(), - frame->append(argument))); + frame->push(types.object, + c->call(c->constant(getThunk(t, thunk), types.address), + 0, + frame->trace(0, 0), + types.object, + 2, + c->threadRegister(), + frame->append(argument))); } break; case newarray: { uint8_t type = codeBody(t, code, ip++); - ir::Value* length = frame->popInt(); + ir::Value* length = frame->pop(types.i4); - frame->pushObject( + frame->push( + types.object, c->call(c->constant(getThunk(t, makeBlankArrayThunk), types.address), 0, frame->trace(0, 0), @@ -5790,7 +5763,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, table = frame->append(staticTable); } else { - table = frame->popObject(); + table = frame->pop(types.object); } switch (fieldCode) { @@ -5903,7 +5876,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->append(pair), value); } else { - ir::Value* instance = frame->popObject(); + ir::Value* instance = frame->pop(types.object); c->call(c->constant(getThunk(t, setFieldValueFromReferenceThunk), types.address), @@ -5933,7 +5906,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, static_cast(0), value); } else { - ir::Value* instance = frame->popObject(); + ir::Value* instance = frame->pop(types.object); c->call( c->constant(getThunk(t, setLongFieldValueFromReferenceThunk), @@ -5964,7 +5937,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->append(pair), value); } else { - ir::Value* instance = frame->popObject(); + ir::Value* instance = frame->pop(types.object); c->call( c->constant(getThunk(t, setObjectFieldValueFromReferenceThunk), @@ -6003,8 +5976,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, goto next; case sipush: - frame->pushInt(c->constant( - static_cast(codeReadInt16(t, code, ip)), types.i4)); + frame->push(types.i4, + c->constant(static_cast(codeReadInt16(t, code, ip)), + types.i4)); break; case swap: @@ -6041,7 +6015,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } assert(t, start); - ir::Value* key = frame->popInt(); + ir::Value* key = frame->pop(types.i4); c->condJump(lir::JumpIfLess, c->constant(bottom, types.i4), @@ -6064,7 +6038,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case astore: { - frame->storeObject(codeReadInt16(t, code, ip)); + frame->store(types.object, codeReadInt16(t, code, ip)); } break; case iinc: { @@ -6082,11 +6056,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case iload: { - frame->loadInt(codeReadInt16(t, code, ip)); + frame->load(types.i4, codeReadInt16(t, code, ip)); } break; case istore: { - frame->storeInt(codeReadInt16(t, code, ip)); + frame->store(types.i4, codeReadInt16(t, code, ip)); } break; case lload: { From 1d86e668cbba4a42338834fa66f387e73823eebf Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Mon, 5 May 2014 15:49:25 -0600 Subject: [PATCH 83/89] inline Frame::*ed* code --- src/compile.cpp | 303 ++++++++++++++++++------------------------------ 1 file changed, 110 insertions(+), 193 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index dbcacf6eb9..c13ddf4e96 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1474,112 +1474,6 @@ class Frame { } } - void storedInt(unsigned index) { - assert(t, index < localSize()); - set(index, types.i4); - } - - void storedLong(unsigned index) { - assert(t, index + 1 < localSize()); - set(index, types.i8); - set(index + 1, types.i8); - } - - void dupped() { - assert(t, sp + 1 <= frameSize()); - assert(t, sp - 1 >= localSize()); - set(sp, get(sp - 1)); - ++ sp; - } - - void duppedX1() { - assert(t, sp + 1 <= frameSize()); - assert(t, sp - 2 >= localSize()); - - ir::Type b2 = get(sp - 2); - ir::Type b1 = get(sp - 1); - - set(sp - 1, b2); - set(sp - 2, b1); - set(sp , b1); - - ++ sp; - } - - void duppedX2() { - assert(t, sp + 1 <= frameSize()); - assert(t, sp - 3 >= localSize()); - - ir::Type b3 = get(sp - 3); - ir::Type b2 = get(sp - 2); - ir::Type b1 = get(sp - 1); - - set(sp - 2, b3); - set(sp - 1, b2); - set(sp - 3, b1); - set(sp , b1); - - ++ sp; - } - - void dupped2() { - assert(t, sp + 2 <= frameSize()); - assert(t, sp - 2 >= localSize()); - - ir::Type b2 = get(sp - 2); - ir::Type b1 = get(sp - 1); - - set(sp, b2); - set(sp + 1, b1); - - sp += 2; - } - - void dupped2X1() { - assert(t, sp + 2 <= frameSize()); - assert(t, sp - 3 >= localSize()); - - ir::Type b3 = get(sp - 3); - ir::Type b2 = get(sp - 2); - ir::Type b1 = get(sp - 1); - - set(sp - 1, b3); - set(sp - 3, b2); - set(sp , b2); - set(sp - 2, b1); - set(sp + 1, b1); - - sp += 2; - } - - void dupped2X2() { - assert(t, sp + 2 <= frameSize()); - assert(t, sp - 4 >= localSize()); - - ir::Type b4 = get(sp - 4); - ir::Type b3 = get(sp - 3); - ir::Type b2 = get(sp - 2); - ir::Type b1 = get(sp - 1); - - set(sp - 2, b4); - set(sp - 1, b3); - set(sp - 4, b2); - set(sp , b2); - set(sp - 3, b1); - set(sp + 1, b1); - - sp += 2; - } - - void swapped() { - assert(t, sp - 2 >= localSize()); - - ir::Type saved = get(sp - 1); - - set(sp - 1, get(sp - 2)); - set(sp - 2, saved); - } - avian::codegen::Promise* addressPromise(avian::codegen::Promise* p) { BootContext* bc = context->bootContext; if (bc) { @@ -1652,26 +1546,6 @@ class Frame { this->ip = bytecodeIp; } - // void c->push(ir::Type type, ir::Value* o) - // { - // c->push(type, o); - // } - - // void c->push(types.i8, ir::Value* o) - // { - // c->push(types.i8, o); - // } - - // ir::Value* c->pop(ir::Type type) - // { - // return c->pop(type); - // } - - // ir::Value* c->pop(types.i8) - // { - // return c->pop(types.i8); - // } - void push(ir::Type type, ir::Value* o) { assert(t, type == o->type); @@ -1696,16 +1570,6 @@ class Frame { set(sp++, type); } - // void pushLarge(types.i8, ir::Value* o) - // { - // pushLarge(types.i8, o); - // } - - // void pushLarge(types.f8, ir::Value* o) - // { - // pushLarge(types.f8, o); - // } - void pop(unsigned count) { popped(count); c->popped(count); @@ -1736,20 +1600,9 @@ class Frame { push(type, loadLocal(context, 1, type, index)); } - void loadLong(unsigned index) { + void loadLarge(ir::Type type, unsigned index) { assert(t, index < static_cast(localSize() - 1)); - pushLarge(types.i8, loadLocal(context, 2, types.i8, index)); - } - - void loadDouble(unsigned index) - { - assert(t, index < static_cast(localSize() - 1)); - pushLarge(types.f8, loadLocal(context, 2, types.f8, index)); - } - - void loadObject(unsigned index) { - assert(t, index < localSize()); - push(types.object, loadLocal(context, 1, types.object, index)); + pushLarge(type, loadLocal(context, 2, type, index)); } void store(ir::Type type, unsigned index) @@ -1761,21 +1614,21 @@ class Frame { set(ti, type); } - void storeLong(unsigned index) { - storeLocal(context, 2, types.i8, popLarge(types.i8), index); - storedLong(translateLocalIndex(context, 2, index)); - } - - void storeDouble(unsigned index) - { - storeLocal(context, 2, types.f8, popLarge(types.f8), index); - storedLong(translateLocalIndex(context, 2, index)); + void storeLarge(ir::Type type, unsigned index) { + storeLocal(context, 2, type, popLarge(type), index); + unsigned ti = translateLocalIndex(context, 2, index); + assert(t, ti + 1 < localSize()); + set(ti, type); + set(ti + 1, type); } void dup() { c->push(types.i4, c->peek(1, 0)); - dupped(); + assert(t, sp + 1 <= frameSize()); + assert(t, sp - 1 >= localSize()); + set(sp, get(sp - 1)); + ++ sp; } void dupX1() { @@ -1786,7 +1639,17 @@ class Frame { c->push(types.i4, s1); c->push(types.i4, s0); - duppedX1(); + assert(t, sp + 1 <= frameSize()); + assert(t, sp - 2 >= localSize()); + + ir::Type b2 = get(sp - 2); + ir::Type b1 = get(sp - 1); + + set(sp - 1, b2); + set(sp - 2, b1); + set(sp , b1); + + ++ sp; } void dupX2() { @@ -1808,7 +1671,19 @@ class Frame { c->push(types.i4, s0); } - duppedX2(); + assert(t, sp + 1 <= frameSize()); + assert(t, sp - 3 >= localSize()); + + ir::Type b3 = get(sp - 3); + ir::Type b2 = get(sp - 2); + ir::Type b1 = get(sp - 1); + + set(sp - 2, b3); + set(sp - 1, b2); + set(sp - 3, b1); + set(sp , b1); + + ++ sp; } void dup2() { @@ -1824,7 +1699,16 @@ class Frame { c->push(types.i4, s0); } - dupped2(); + assert(t, sp + 2 <= frameSize()); + assert(t, sp - 2 >= localSize()); + + ir::Type b2 = get(sp - 2); + ir::Type b1 = get(sp - 1); + + set(sp, b2); + set(sp + 1, b1); + + sp += 2; } void dup2X1() { @@ -1847,7 +1731,20 @@ class Frame { c->push(types.i4, s0); } - dupped2X1(); + assert(t, sp + 2 <= frameSize()); + assert(t, sp - 3 >= localSize()); + + ir::Type b3 = get(sp - 3); + ir::Type b2 = get(sp - 2); + ir::Type b1 = get(sp - 1); + + set(sp - 1, b3); + set(sp - 3, b2); + set(sp , b2); + set(sp - 2, b1); + set(sp + 1, b1); + + sp += 2; } void dup2X2() { @@ -1883,7 +1780,22 @@ class Frame { c->push(types.i4, s0); } - dupped2X2(); + assert(t, sp + 2 <= frameSize()); + assert(t, sp - 4 >= localSize()); + + ir::Type b4 = get(sp - 4); + ir::Type b3 = get(sp - 3); + ir::Type b2 = get(sp - 2); + ir::Type b1 = get(sp - 1); + + set(sp - 2, b4); + set(sp - 1, b3); + set(sp - 4, b2); + set(sp , b2); + set(sp - 3, b1); + set(sp + 1, b1); + + sp += 2; } void swap() { @@ -1893,7 +1805,12 @@ class Frame { c->push(types.i4, s0); c->push(types.i4, s1); - swapped(); + assert(t, sp - 2 >= localSize()); + + ir::Type saved = get(sp - 1); + + set(sp - 1, get(sp - 2)); + set(sp - 2, saved); } TraceElement* trace(object target, unsigned flags) { @@ -4190,23 +4107,23 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case aload: - frame->loadObject(codeBody(t, code, ip++)); + frame->load(types.object, codeBody(t, code, ip++)); break; case aload_0: - frame->loadObject(0); + frame->load(types.object, 0); break; case aload_1: - frame->loadObject(1); + frame->load(types.object, 1); break; case aload_2: - frame->loadObject(2); + frame->load(types.object, 2); break; case aload_3: - frame->loadObject(3); + frame->load(types.object, 3); break; case anewarray: { @@ -5395,38 +5312,38 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lload: - frame->loadLong(codeBody(t, code, ip++)); + frame->loadLarge(types.i8, codeBody(t, code, ip++)); break; case dload: - frame->loadDouble(codeBody(t, code, ip++)); + frame->loadLarge(types.f8, codeBody(t, code, ip++)); break; case lload_0: - frame->loadLong(0); + frame->loadLarge(types.i8, 0); break; case dload_0: - frame->loadDouble(0); + frame->loadLarge(types.f8, 0); break; case lload_1: - frame->loadLong(1); + frame->loadLarge(types.i8, 1); break; case dload_1: - frame->loadDouble(1); + frame->loadLarge(types.f8, 1); break; case lload_2: - frame->loadLong(2); + frame->loadLarge(types.i8, 2); break; case dload_2: - frame->loadDouble(2); + frame->loadLarge(types.f8, 2); break; case lload_3: - frame->loadLong(3); + frame->loadLarge(types.i8, 3); break; case dload_3: - frame->loadDouble(3); + frame->loadLarge(types.f8, 3); break; case lneg: @@ -5534,38 +5451,38 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lstore: - frame->storeLong(codeBody(t, code, ip++)); + frame->storeLarge(types.i8, codeBody(t, code, ip++)); break; case dstore: - frame->storeDouble(codeBody(t, code, ip++)); + frame->storeLarge(types.f8, codeBody(t, code, ip++)); break; case lstore_0: - frame->storeLong(0); + frame->storeLarge(types.i8, 0); break; case dstore_0: - frame->storeDouble(0); + frame->storeLarge(types.f8, 0); break; case lstore_1: - frame->storeLong(1); + frame->storeLarge(types.i8, 1); break; case dstore_1: - frame->storeDouble(1); + frame->storeLarge(types.f8, 1); break; case lstore_2: - frame->storeLong(2); + frame->storeLarge(types.i8, 2); break; case dstore_2: - frame->storeDouble(2); + frame->storeLarge(types.f8, 2); break; case lstore_3: - frame->storeLong(3); + frame->storeLarge(types.i8, 3); break; case dstore_3: - frame->storeDouble(3); + frame->storeLarge(types.f8, 3); break; case monitorenter: { @@ -6034,7 +5951,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case wide: { switch (codeBody(t, code, ip++)) { case aload: { - frame->loadObject(codeReadInt16(t, code, ip)); + frame->load(types.object, codeReadInt16(t, code, ip)); } break; case astore: { @@ -6064,11 +5981,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lload: { - frame->loadLong(codeReadInt16(t, code, ip)); + frame->loadLarge(types.i8, codeReadInt16(t, code, ip)); } break; case lstore: { - frame->storeLong(codeReadInt16(t, code, ip)); + frame->storeLarge(types.i8, codeReadInt16(t, code, ip)); } break; case ret: { From a35e47b6fb710a84b3f2d5d4a16d8ba0f1fd3bbc Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 31 May 2014 11:18:42 -0600 Subject: [PATCH 84/89] add 'mode=debug bootimage=true' test to ci.sh --- test/ci.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/ci.sh b/test/ci.sh index a2fd8492a5..f64c13939b 100755 --- a/test/ci.sh +++ b/test/ci.sh @@ -24,6 +24,7 @@ run make ${flags} process=interpret ${test_target} # bootimage and openjdk builds without openjdk-src don't work: if [ -z "${openjdk}" ]; then run make ${flags} bootimage=true ${test_target} + run make ${flags} mode=debug bootimage=true ${test_target} # might as well do an openjdk test while we're here: run make openjdk=$JAVA_HOME ${flags} ${test_target} fi From 9ed6a1634098d9f5ef0a99cf8d3f60e203c2573a Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 31 May 2014 19:39:36 -0600 Subject: [PATCH 85/89] make function and constant naming clearer (code review feedback) --- src/codegen/compiler/event.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 90c95dc45b..e24cd0695e 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -208,6 +208,7 @@ struct SliceStack : public Slice { void push(const T& item) { + ASSERT(Slice::count < capacity); --Slice::items; ++Slice::count; *Slice::items = item; @@ -223,7 +224,7 @@ struct FixedSliceStack : public SliceStack { } }; -Value* pushWordSlice(Context* c, +Value* slicePushWord(Context* c, Value* v, size_t stackBase UNUSED, SliceStack& slice) @@ -248,7 +249,7 @@ Value* pushWordSlice(Context* c, return v; } -void pushSlice(Context* c, +void slicePush(Context* c, unsigned footprint, Value* v, size_t stackBase, @@ -261,7 +262,7 @@ void pushSlice(Context* c, Value* low = v; if (bigEndian) { - v = pushWordSlice(c, v, stackBase, slice); + v = slicePushWord(c, v, stackBase, slice); } Value* high; @@ -270,16 +271,16 @@ void pushSlice(Context* c, if (vm::TargetBytesPerWord == 4) { low->maybeSplit(c); - high = pushWordSlice(c, low->nextWord, stackBase, slice); + high = slicePushWord(c, low->nextWord, stackBase, slice); } else { - high = pushWordSlice(c, 0, stackBase, slice); + high = slicePushWord(c, 0, stackBase, slice); } } else { high = 0; } if (not bigEndian) { - v = pushWordSlice(c, v, stackBase, slice); + v = slicePushWord(c, v, stackBase, slice); } if (high) { @@ -1066,7 +1067,8 @@ void appendCombine(Context* c, &thunk); if (thunk) { - FixedSliceStack slice; + const size_t MaxValueCount = 6; + FixedSliceStack slice; size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; @@ -1078,12 +1080,12 @@ void appendCombine(Context* c, unsigned stackSize = ceilingDivide(secondValue->type.size(), vm::TargetBytesPerWord) + ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord); - pushSlice(c, + slicePush(c, ceilingDivide(secondValue->type.size(), vm::TargetBytesPerWord), secondValue, stackBase, slice); - pushSlice(c, + slicePush(c, ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), firstValue, stackBase, @@ -1092,7 +1094,7 @@ void appendCombine(Context* c, if (threadParameter) { ++ stackSize; - pushSlice(c, 1, threadRegister(c), stackBase, slice); + slicePush(c, 1, threadRegister(c), stackBase, slice); } appendCall(c, @@ -1221,7 +1223,7 @@ void appendTranslate(Context* c, size_t stackBase = c->stack ? c->stack->index + 1 : 0; FixedSliceStack slice; - pushSlice(c, + slicePush(c, ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), firstValue, stackBase, @@ -1608,7 +1610,8 @@ void appendBranch(Context* c, &thunk); if (thunk) { - FixedSliceStack slice; + const size_t MaxValueCount = 4; + FixedSliceStack slice; size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; @@ -1617,12 +1620,12 @@ void appendBranch(Context* c, assert(c, not threadParameter); - pushSlice(c, + slicePush(c, ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), secondValue, stackBase, slice); - pushSlice(c, + slicePush(c, ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), firstValue, stackBase, From ec2e153aa879a31a32ce7900a65b6e9ca4ac5f74 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 31 May 2014 21:28:27 -0600 Subject: [PATCH 86/89] fixup comments in Subroutine --- src/compile.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index c13ddf4e96..6e1353883a 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -774,7 +774,7 @@ class Subroutine { // Index of this subroutine, in the (unmaterialized) list of subroutines in // this method. - // Note that in the presence of nested finalls, this could theoretically end + // Note that in the presence of nested finallys, this could theoretically end // up being greater than the number of jsr instructions (but this will be // extremely rare - I don't think we've seen this in practice). const unsigned index; @@ -782,10 +782,6 @@ class Subroutine { // Subroutine outer to this one (if, for instance, we have nested finallys) Subroutine* const outer; - // How many levels deep of subroutines we're nested in. - // Note: This should always be len(outer), when treated as a list. - // const unsigned nesting; - // Starting ip in the original bytecode (always < original bytecode size) const unsigned returnAddress; From 68b725900ea2ed92ceeab8c8f7a54d5853f5e966 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sun, 1 Jun 2014 10:04:56 -0600 Subject: [PATCH 87/89] remove old Subroutine comments --- src/compile.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 6e1353883a..1f9a3421bc 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -6623,8 +6623,7 @@ void copyFrameMap(int32_t* dst, uintptr_t* src, unsigned mapSizeInBits, unsigned offset, - TraceElement* p /*, - SubroutinePath* subroutinePath*/) + TraceElement* p) { if (DebugFrameMaps) { fprintf(stderr, " orig roots at ip %3d: ", p->ip); @@ -6853,16 +6852,8 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) qsort(RUNTIME_ARRAY_BODY(elements), index, sizeof(TraceElement*), compareTraceElementPointers); - object map; - // if (pathFootprint) { - // map = makeGeneralFrameMapTable - // (t, context, start, RUNTIME_ARRAY_BODY(elements), index, - // pathFootprint, - // mapCount); - // } else { - map = makeSimpleFrameMapTable - (t, context, start, RUNTIME_ARRAY_BODY(elements), index); - // } + object map = makeSimpleFrameMapTable( + t, context, start, RUNTIME_ARRAY_BODY(elements), index); set(t, methodCode(t, context->method), CodePool, map); } From 1fb6a0bceb6e9c06c4e5acb4413002ad244e0acf Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sun, 1 Jun 2014 14:22:14 -0600 Subject: [PATCH 88/89] fix up creation of ir::Type --- include/avian/codegen/ir.h | 130 +-- src/codegen/compiler.cpp | 56 +- src/codegen/compiler/event.cpp | 249 +++--- src/compile.cpp | 1440 +++++++++++++++++--------------- 4 files changed, 999 insertions(+), 876 deletions(-) diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h index 54ac8e0982..ae95a2efa5 100644 --- a/include/avian/codegen/ir.h +++ b/include/avian/codegen/ir.h @@ -15,6 +15,15 @@ namespace avian { namespace codegen { namespace ir { +class TargetInfo { + public: + unsigned pointerSize; + + TargetInfo(unsigned pointerSize) : pointerSize(pointerSize) + { + } +}; + class Type { public: enum Flavor { @@ -36,30 +45,90 @@ class Type { Void, }; + typedef int16_t TypeDesc; + +#define TY_DESC(flavor, size) ((flavor & 0xff) | ((size & 0xff) << 8)) + // TODO: once we upgrade to c++11, these should become plain constants (rather + // than function calls). + // The constructor will need to be declared 'constexpr'. + static inline Type void_() + { + return TY_DESC(Void, 0); + } + static inline Type object() + { + return TY_DESC(Object, -1); + } + static inline Type iptr() + { + return TY_DESC(Integer, -1); + } + static inline Type i1() + { + return TY_DESC(Integer, 1); + } + static inline Type i2() + { + return TY_DESC(Integer, 2); + } + static inline Type i4() + { + return TY_DESC(Integer, 4); + } + static inline Type i8() + { + return TY_DESC(Integer, 8); + } + static inline Type f4() + { + return TY_DESC(Float, 4); + } + static inline Type f8() + { + return TY_DESC(Float, 8); + } + static inline Type addr() + { + return TY_DESC(Address, -1); + } +#undef TY_DESC + private: - uint8_t flavor_; - uint8_t size_; + TypeDesc desc; friend class Types; - public: - Type(uint8_t flavor_, uint8_t size_) : flavor_(flavor_), size_(size_) + // TODO: once we move to c++11, declare this 'constexpr', to allow + // compile-time constants of this type. + /* constexpr */ Type(TypeDesc desc) : desc(desc) { } + public: inline Flavor flavor() const { - return (Flavor)flavor_; + return (Flavor)(desc & 0xff); } - inline unsigned size() const + // If the size isn't known without inspecting the TargetInfo, returns -1. + // Otherwise, matches size(TargetInfo). + inline int rawSize() const { - return size_; + return desc >> 8; + } + + inline unsigned size(const TargetInfo& t) const + { + int s = rawSize(); + if (s < 0) { + return t.pointerSize; + } + return (unsigned)s; } inline bool operator==(const Type& other) const { - return flavor_ == other.flavor_ && size_ == other.size_; + return desc == other.desc; } inline bool operator!=(const Type& other) const @@ -68,51 +137,6 @@ class Type { } }; -class Types { - public: - // An object reference type, which will be treated as a GC root - Type object; - - // A pointer-sized integer type (neither/both signed or unsigned) - // Note that these are just integers from the GC's perspective. - Type address; - - // A 1-byte integer type (neither/both signed or unsigned) - Type i1; - - // A 2-byte integer type (neither/both signed or unsigned) - Type i2; - - // A 4-byte integer type (neither/both signed or unsigned) - Type i4; - - // A 8-byte integer type (neither/both signed or unsigned) - Type i8; - - // A 4-byte floating point type - Type f4; - - // A 8-byte floating point type - Type f8; - - // A type representing the lack of a return value - // TODO: remove when possible - Type void_; - - Types(unsigned bytesPerWord) - : object(Type::Object, bytesPerWord), - address(Type::Integer, bytesPerWord), - i1(Type::Integer, 1), - i2(Type::Integer, 2), - i4(Type::Integer, 4), - i8(Type::Integer, 8), - f4(Type::Float, 4), - f8(Type::Float, 8), - void_(Type::Void, 0) - { - } -}; - enum SignExtendMode { SignExtend, ZeroExtend }; enum CallingConvention { NativeCallingConvention, AvianCallingConvention }; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 019c139eb6..dc9bbdbe4b 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -1220,7 +1220,7 @@ unsigned typeFootprint(Context* c, ir::Type type) switch (type.flavor()) { case ir::Type::Float: case ir::Type::Integer: - return type.size() / 4; + return type.rawSize() / 4; case ir::Type::Object: case ir::Type::Address: case ir::Type::Half: @@ -1258,7 +1258,7 @@ Value* loadLocal(Context* c, ir::Type type, unsigned index) Value* threadRegister(Context* c) { Site* s = registerSite(c, c->arch->thread()); - return value(c, ir::Type(ir::Type::Address, TargetBytesPerWord), s, s); + return value(c, ir::Type::addr(), s, s); } unsigned @@ -1518,7 +1518,7 @@ resolveOriginalSites(Context* c, Event* e, SiteRecordList* frozen, buffer, v, el.localIndex, el.frameIndex(c)); } - Value dummy(0, 0, ir::Type(ir::Type::Integer, TargetBytesPerWord)); + Value dummy(0, 0, ir::Type::addr()); dummy.addSite(c, s); dummy.removeSite(c, s); freeze(c, frozen, s, 0); @@ -2281,7 +2281,7 @@ class MyCompiler: public Compiler { static_cast(base), displacement, static_cast(index), - index == 0 ? 1 : type.size(), + index == 0 ? 1 : type.size(TargetBytesPerWord), result); return result; @@ -2315,8 +2315,7 @@ class MyCompiler: public Compiler { assert(&c, footprint == 2); assert(&c, static_cast(value)->nextWord); - save(ir::Type(ir::Type::Integer, 4), - static_cast(value)->nextWord); + save(ir::Type::i4(), static_cast(value)->nextWord); } } @@ -2582,14 +2581,14 @@ class MyCompiler: public Compiler { { assert(&c, src->type.flavor() == type.flavor()); assert(&c, type.flavor() != ir::Type::Float); - assert(&c, type.size() < src->type.size()); + assert(&c, type.rawSize() < src->type.rawSize()); Value* dst = value(&c, type); appendMove(&c, lir::Move, - src->type.size(), - src->type.size(), + src->type.size(TargetBytesPerWord), + src->type.size(TargetBytesPerWord), static_cast(src), - type.size(), + type.size(TargetBytesPerWord), dst); return dst; } @@ -2603,10 +2602,11 @@ class MyCompiler: public Compiler { appendMove(&c, signExtend == ir::SignExtend ? lir::Move : lir::MoveZ, TargetBytesPerWord, - truncateType.size(), + truncateType.size(TargetBytesPerWord), static_cast(src), - extendType.size() < TargetBytesPerWord ? TargetBytesPerWord - : extendType.size(), + extendType.size(TargetBytesPerWord) < TargetBytesPerWord + ? TargetBytesPerWord + : extendType.size(TargetBytesPerWord), dst); return dst; } @@ -2617,10 +2617,10 @@ class MyCompiler: public Compiler { appendMove(&c, lir::Move, - src->type.size(), - src->type.size(), + src->type.size(TargetBytesPerWord), + src->type.size(TargetBytesPerWord), static_cast(src), - dst->type.size(), + dst->type.size(TargetBytesPerWord), static_cast(dst)); } @@ -2633,11 +2633,12 @@ class MyCompiler: public Compiler { Value* dst = value(&c, dstType); appendMove(&c, signExtend == ir::SignExtend ? lir::Move : lir::MoveZ, - src->type.size(), - src->type.size(), + src->type.size(TargetBytesPerWord), + src->type.size(TargetBytesPerWord), static_cast(src), - dstType.size() < TargetBytesPerWord ? TargetBytesPerWord - : dstType.size(), + dstType.size(TargetBytesPerWord) < TargetBytesPerWord + ? TargetBytesPerWord + : dstType.size(TargetBytesPerWord), dst); return dst; } @@ -2645,31 +2646,30 @@ class MyCompiler: public Compiler { virtual void condJump(lir::TernaryOperation op, ir::Value* a, ir::Value* b, - ir::Value* address) + ir::Value* addr) { assert(&c, (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or( isFloatBranch(op) and isFloatValue(a) and isFloatValue(b))); assert(&c, a->type == b->type); - assert(&c, - address->type == ir::Type(ir::Type::Integer, TargetBytesPerWord)); + assert(&c, addr->type == ir::Type::iptr()); appendBranch(&c, op, static_cast(a), static_cast(b), - static_cast(address)); + static_cast(addr)); } - virtual void jmp(ir::Value* address) + virtual void jmp(ir::Value* addr) { - appendJump(&c, lir::Jump, static_cast(address)); + appendJump(&c, lir::Jump, static_cast(addr)); } - virtual void exit(ir::Value* address) + virtual void exit(ir::Value* addr) { - appendJump(&c, lir::Jump, static_cast(address), true); + appendJump(&c, lir::Jump, static_cast(addr), true); } virtual ir::Value* binaryOp(lir::TernaryOperation op, diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index e24cd0695e..d4045b9aab 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -576,9 +576,10 @@ class CallEvent: public Event { clean(c, this, stackBefore, localsBefore, reads, popIndex); - if (resultValue->type.size() and live(c, resultValue)) { + if (resultValue->type.size(vm::TargetBytesPerWord) + and live(c, resultValue)) { resultValue->addSite(c, registerSite(c, c->arch->returnLow())); - if (resultValue->type.size() + if (resultValue->type.size(vm::TargetBytesPerWord) > vm::TargetBytesPerWord and live(c, resultValue->nextWord)) { resultValue->nextWord->addSite(c, registerSite(c, c->arch->returnHigh())); @@ -627,7 +628,7 @@ class ReturnEvent: public Event { if (value) { this->addReads(c, value, - value->type.size(), + value->type.size(vm::TargetBytesPerWord), SiteMask::fixedRegisterMask(c->arch->returnLow()), SiteMask::fixedRegisterMask(c->arch->returnHigh())); } @@ -945,17 +946,26 @@ class CombineEvent: public Event { secondValue(secondValue), resultValue(resultValue) { - this->addReads(c, firstValue, firstValue->type.size(), firstLowMask, firstHighMask); + this->addReads(c, + firstValue, + firstValue->type.size(vm::TargetBytesPerWord), + firstLowMask, + firstHighMask); - if (resultValue->type.size() > vm::TargetBytesPerWord) { + if (resultValue->type.size(vm::TargetBytesPerWord) + > vm::TargetBytesPerWord) { resultValue->grow(c); } bool condensed = c->arch->alwaysCondensed(op); - this->addReads(c, secondValue, secondValue->type.size(), - secondLowMask, condensed ? resultValue : 0, - secondHighMask, condensed ? resultValue->nextWord : 0); + this->addReads(c, + secondValue, + secondValue->type.size(vm::TargetBytesPerWord), + secondLowMask, + condensed ? resultValue : 0, + secondHighMask, + condensed ? resultValue->nextWord : 0); } virtual const char* name() { @@ -973,28 +983,28 @@ class CombineEvent: public Event { // } assert(c, secondValue->source->type(c) == secondValue->nextWord->source->type(c)); - - freezeSource(c, firstValue->type.size(), firstValue); - + + freezeSource(c, firstValue->type.size(vm::TargetBytesPerWord), firstValue); + OperandMask cMask; c->arch->planDestination( op, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), OperandMask( 1 << firstValue->source->type(c), (static_cast( firstValue->nextWord->source->registerMask(c)) << 32) | static_cast(firstValue->source->registerMask(c))), - secondValue->type.size(), + secondValue->type.size(vm::TargetBytesPerWord), OperandMask( 1 << secondValue->source->type(c), (static_cast( secondValue->nextWord->source->registerMask(c)) << 32) | static_cast(secondValue->source->registerMask(c))), - resultValue->type.size(), + resultValue->type.size(vm::TargetBytesPerWord), cMask); SiteMask resultLowMask = SiteMask::lowPart(cMask); @@ -1002,10 +1012,12 @@ class CombineEvent: public Event { Site* low = getTarget(c, secondValue, resultValue, resultLowMask); unsigned lowSize = low->registerSize(c); - Site* high - = (resultValue->type.size() > lowSize - ? getTarget(c, secondValue->nextWord, resultValue->nextWord, resultHighMask) - : low); + Site* high = (resultValue->type.size(vm::TargetBytesPerWord) > lowSize + ? getTarget(c, + secondValue->nextWord, + resultValue->nextWord, + resultHighMask) + : low); // fprintf(stderr, "combine %p:%p and %p:%p into %p:%p\n", // firstValue, firstValue->nextWord, @@ -1014,30 +1026,31 @@ class CombineEvent: public Event { apply(c, op, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), firstValue->source, firstValue->nextWord->source, - secondValue->type.size(), + secondValue->type.size(vm::TargetBytesPerWord), secondValue->source, secondValue->nextWord->source, - resultValue->type.size(), + resultValue->type.size(vm::TargetBytesPerWord), low, high); - thawSource(c, firstValue->type.size(), firstValue); + thawSource(c, firstValue->type.size(vm::TargetBytesPerWord), firstValue); for (Read* r = reads; r; r = r->eventNext) { popRead(c, this, r->value); } low->thaw(c, secondValue); - if (resultValue->type.size() > lowSize) { + if (resultValue->type.size(vm::TargetBytesPerWord) > lowSize) { high->thaw(c, secondValue->nextWord); } if (live(c, resultValue)) { resultValue->addSite(c, low); - if (resultValue->type.size() > lowSize and live(c, resultValue->nextWord)) { + if (resultValue->type.size(vm::TargetBytesPerWord) > lowSize + and live(c, resultValue->nextWord)) { resultValue->nextWord->addSite(c, high); } } @@ -1059,11 +1072,11 @@ void appendCombine(Context* c, OperandMask firstMask; OperandMask secondMask; c->arch->planSource(op, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), firstMask, - secondValue->type.size(), + secondValue->type.size(vm::TargetBytesPerWord), secondMask, - resultValue->type.size(), + resultValue->type.size(vm::TargetBytesPerWord), &thunk); if (thunk) { @@ -1072,21 +1085,27 @@ void appendCombine(Context* c, size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; - intptr_t handler = c->client->getThunk(op, - firstValue->type.size(), - resultValue->type.size(), - &threadParameter); + intptr_t handler + = c->client->getThunk(op, + firstValue->type.size(vm::TargetBytesPerWord), + resultValue->type.size(vm::TargetBytesPerWord), + &threadParameter); - unsigned stackSize = ceilingDivide(secondValue->type.size(), vm::TargetBytesPerWord) - + ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord); + unsigned stackSize + = ceilingDivide(secondValue->type.size(vm::TargetBytesPerWord), + vm::TargetBytesPerWord) + + ceilingDivide(firstValue->type.size(vm::TargetBytesPerWord), + vm::TargetBytesPerWord); slicePush(c, - ceilingDivide(secondValue->type.size(), vm::TargetBytesPerWord), + ceilingDivide(secondValue->type.size(vm::TargetBytesPerWord), + vm::TargetBytesPerWord), secondValue, stackBase, slice); slicePush(c, - ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(vm::TargetBytesPerWord), + vm::TargetBytesPerWord), firstValue, stackBase, slice); @@ -1098,9 +1117,7 @@ void appendCombine(Context* c, } appendCall(c, - value(c, - ir::Type(ir::Type::Address, vm::TargetBytesPerWord), - constantSite(c, handler)), + value(c, ir::Type::addr(), constantSite(c, handler)), ir::NativeCallingConvention, 0, 0, @@ -1132,12 +1149,18 @@ class TranslateEvent: public Event { { bool condensed = c->arch->alwaysCondensed(op); - if (resultValue->type.size() > vm::TargetBytesPerWord) { + if (resultValue->type.size(vm::TargetBytesPerWord) + > vm::TargetBytesPerWord) { resultValue->grow(c); } - this->addReads(c, firstValue, firstValue->type.size(), valueLowMask, condensed ? resultValue : 0, - valueHighMask, condensed ? resultValue->nextWord : 0); + this->addReads(c, + firstValue, + firstValue->type.size(vm::TargetBytesPerWord), + valueLowMask, + condensed ? resultValue : 0, + valueHighMask, + condensed ? resultValue->nextWord : 0); } virtual const char* name() { @@ -1151,14 +1174,14 @@ class TranslateEvent: public Event { c->arch->planDestination( op, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), OperandMask( 1 << firstValue->source->type(c), (static_cast( firstValue->nextWord->source->registerMask(c)) << 32) | static_cast(firstValue->source->registerMask(c))), - resultValue->type.size(), + resultValue->type.size(vm::TargetBytesPerWord), bMask); SiteMask resultLowMask = SiteMask::lowPart(bMask); @@ -1166,17 +1189,19 @@ class TranslateEvent: public Event { Site* low = getTarget(c, firstValue, resultValue, resultLowMask); unsigned lowSize = low->registerSize(c); - Site* high - = (resultValue->type.size() > lowSize - ? getTarget(c, firstValue->nextWord, resultValue->nextWord, resultHighMask) - : low); + Site* high = (resultValue->type.size(vm::TargetBytesPerWord) > lowSize + ? getTarget(c, + firstValue->nextWord, + resultValue->nextWord, + resultHighMask) + : low); apply(c, op, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), firstValue->source, firstValue->nextWord->source, - resultValue->type.size(), + resultValue->type.size(vm::TargetBytesPerWord), low, high); @@ -1185,13 +1210,14 @@ class TranslateEvent: public Event { } low->thaw(c, firstValue); - if (resultValue->type.size() > lowSize) { + if (resultValue->type.size(vm::TargetBytesPerWord) > lowSize) { high->thaw(c, firstValue->nextWord); } if (live(c, resultValue)) { resultValue->addSite(c, low); - if (resultValue->type.size() > lowSize and live(c, resultValue->nextWord)) { + if (resultValue->type.size(vm::TargetBytesPerWord) > lowSize + and live(c, resultValue->nextWord)) { resultValue->nextWord->addSite(c, high); } } @@ -1210,38 +1236,47 @@ void appendTranslate(Context* c, Value* firstValue, Value* resultValue) { - assert(c, firstValue->type.size() == firstValue->type.size()); - assert(c, resultValue->type.size() == resultValue->type.size()); + assert(c, + firstValue->type.size(vm::TargetBytesPerWord) + == firstValue->type.size(vm::TargetBytesPerWord)); + assert(c, + resultValue->type.size(vm::TargetBytesPerWord) + == resultValue->type.size(vm::TargetBytesPerWord)); bool thunk; OperandMask first; - c->arch->planSource( - op, firstValue->type.size(), first, resultValue->type.size(), &thunk); + c->arch->planSource(op, + firstValue->type.size(vm::TargetBytesPerWord), + first, + resultValue->type.size(vm::TargetBytesPerWord), + &thunk); if (thunk) { size_t stackBase = c->stack ? c->stack->index + 1 : 0; FixedSliceStack slice; slicePush(c, - ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(vm::TargetBytesPerWord), + vm::TargetBytesPerWord), firstValue, stackBase, slice); - appendCall( - c, - value(c, - ir::Type(ir::Type::Address, vm::TargetBytesPerWord), - constantSite( - c, - c->client->getThunk( - op, firstValue->type.size(), resultValue->type.size()))), - ir::NativeCallingConvention, - 0, - 0, - resultValue, - slice); + appendCall(c, + value(c, + ir::Type::addr(), + constantSite( + c, + c->client->getThunk( + op, + firstValue->type.size(vm::TargetBytesPerWord), + resultValue->type.size(vm::TargetBytesPerWord)))), + ir::NativeCallingConvention, + 0, + 0, + resultValue, + slice); } else { append(c, new (c->zone) TranslateEvent(c, @@ -1507,16 +1542,22 @@ class BranchEvent: public Event { secondValue(secondValue), addressValue(addressValue) { - this->addReads( - c, firstValue, firstValue->type.size(), firstLowMask, firstHighMask); - this->addReads( - c, secondValue, firstValue->type.size(), secondLowMask, secondHighMask); + this->addReads(c, + firstValue, + firstValue->type.size(vm::TargetBytesPerWord), + firstLowMask, + firstHighMask); + this->addReads(c, + secondValue, + firstValue->type.size(vm::TargetBytesPerWord), + secondLowMask, + secondHighMask); OperandMask dstMask; c->arch->planDestination(op, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), OperandMask(0, 0), - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), OperandMask(0, 0), vm::TargetBytesPerWord, dstMask); @@ -1541,7 +1582,8 @@ class BranchEvent: public Event { int64_t firstConstVal = firstConstant->value->value(); int64_t secondConstVal = secondConstant->value->value(); - if (firstValue->type.size() > vm::TargetBytesPerWord) { + if (firstValue->type.size(vm::TargetBytesPerWord) + > vm::TargetBytesPerWord) { firstConstVal |= findConstantSite (c, firstValue->nextWord)->value->value() << 32; secondConstVal |= findConstantSite @@ -1550,22 +1592,24 @@ class BranchEvent: public Event { if (shouldJump(c, op, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), firstConstVal, secondConstVal)) { apply(c, lir::Jump, vm::TargetBytesPerWord, addressValue->source, addressValue->source); } } else { - freezeSource(c, firstValue->type.size(), firstValue); - freezeSource(c, firstValue->type.size(), secondValue); + freezeSource( + c, firstValue->type.size(vm::TargetBytesPerWord), firstValue); + freezeSource( + c, firstValue->type.size(vm::TargetBytesPerWord), secondValue); freezeSource(c, vm::TargetBytesPerWord, addressValue); apply(c, op, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), firstValue->source, firstValue->nextWord->source, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), secondValue->source, secondValue->nextWord->source, vm::TargetBytesPerWord, @@ -1573,8 +1617,10 @@ class BranchEvent: public Event { addressValue->source); thawSource(c, vm::TargetBytesPerWord, addressValue); - thawSource(c, firstValue->type.size(), secondValue); - thawSource(c, firstValue->type.size(), firstValue); + thawSource( + c, firstValue->type.size(vm::TargetBytesPerWord), secondValue); + thawSource( + c, firstValue->type.size(vm::TargetBytesPerWord), firstValue); } } @@ -1602,9 +1648,9 @@ void appendBranch(Context* c, OperandMask secondMask; c->arch->planSource(op, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), firstMask, - firstValue->type.size(), + firstValue->type.size(vm::TargetBytesPerWord), secondMask, vm::TargetBytesPerWord, &thunk); @@ -1615,41 +1661,42 @@ void appendBranch(Context* c, size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; - intptr_t handler = c->client->getThunk( - op, firstValue->type.size(), firstValue->type.size(), &threadParameter); + intptr_t handler + = c->client->getThunk(op, + firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(vm::TargetBytesPerWord), + &threadParameter); assert(c, not threadParameter); slicePush(c, - ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(vm::TargetBytesPerWord), + vm::TargetBytesPerWord), secondValue, stackBase, slice); slicePush(c, - ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(vm::TargetBytesPerWord), + vm::TargetBytesPerWord), firstValue, stackBase, slice); - Value* result - = value(c, ir::Type(ir::Type::Address, vm::TargetBytesPerWord)); + Value* result = value(c, ir::Type::addr()); appendCall(c, - value(c, - ir::Type(ir::Type::Address, vm::TargetBytesPerWord), - constantSite(c, handler)), + value(c, ir::Type::addr(), constantSite(c, handler)), ir::NativeCallingConvention, 0, 0, result, slice); - appendBranch(c, - thunkBranch(c, op), - value(c, - ir::Type(ir::Type::Address, vm::TargetBytesPerWord), - constantSite(c, static_cast(0))), - result, - addressValue); + appendBranch( + c, + thunkBranch(c, op), + value(c, ir::Type::addr(), constantSite(c, static_cast(0))), + result, + addressValue); } else { append(c, new (c->zone) BranchEvent(c, diff --git a/src/compile.cpp b/src/compile.cpp index 1f9a3421bc..052df86620 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1287,30 +1287,27 @@ avian::util::FixedAllocator* codeAllocator(MyThread* t); ir::Type operandTypeForFieldCode(Thread* t, unsigned code) { - ir::Types types(TargetBytesPerWord); switch (code) { case ByteField: case BooleanField: - return types.i4; case CharField: case ShortField: - return types.i4; case IntField: - return types.i4; + return ir::Type::i4(); case LongField: - return types.i8; + return ir::Type::i8(); case ObjectField: - return types.object; + return ir::Type::object(); case FloatField: - return types.f4; + return ir::Type::f4(); case DoubleField: - return types.f8; + return ir::Type::f8(); case VoidField: - return types.void_; + return ir::Type::void_(); default: abort(t); @@ -1354,8 +1351,7 @@ class Frame { stackMap(stackMap), ip(0), sp(localSize()), - level(0), - types(TargetBytesPerWord) + level(0) { memset(stackMap, 0, @@ -1370,8 +1366,7 @@ class Frame { stackMap(stackMap), ip(f->ip), sp(f->sp), - level(f->level + 1), - types(TargetBytesPerWord) + level(f->level + 1) { memcpy(stackMap, f->stackMap, @@ -1404,14 +1399,14 @@ class Frame { return c->binaryOp( lir::Add, - types.object, + ir::Type::object(), c->memory( - c->threadRegister(), types.object, TARGET_THREAD_HEAPIMAGE), - c->promiseConstant(p, types.object)); + c->threadRegister(), ir::Type::object(), TARGET_THREAD_HEAPIMAGE), + c->promiseConstant(p, ir::Type::object())); } else { for (PoolElement* e = context->objectPool; e; e = e->next) { if (o == e->target) { - return c->address(types.object, e); + return c->address(ir::Type::object(), e); } } @@ -1419,7 +1414,7 @@ class Frame { ++ context->objectPoolCount; - return c->address(types.object, context->objectPool); + return c->address(ir::Type::object(), context->objectPool); } } @@ -1439,7 +1434,7 @@ class Frame { { assert(t, index < frameSize()); - if (type == types.object) { + if (type == ir::Type::object()) { context->eventLog.append(MarkEvent); context->eventLog.append2(index); } else { @@ -1465,7 +1460,7 @@ class Frame { assert(t, sp >= count); assert(t, sp - count >= localSize()); while (count) { - set(--sp, types.i4); + set(--sp, ir::Type::i4()); -- count; } } @@ -1482,7 +1477,7 @@ class Frame { ir::Value* addressOperand(avian::codegen::Promise* p) { - return c->promiseConstant(p, types.address); + return c->promiseConstant(p, ir::Type::iptr()); } ir::Value* absoluteAddressOperand(avian::codegen::Promise* p) @@ -1490,22 +1485,22 @@ class Frame { return context->bootContext ? c->binaryOp( lir::Add, - types.address, + ir::Type::iptr(), c->memory(c->threadRegister(), - types.address, + ir::Type::iptr(), TARGET_THREAD_CODEIMAGE), c->promiseConstant( new (&context->zone) avian::codegen::OffsetPromise( p, -reinterpret_cast( codeAllocator(t)->memory.begin())), - types.address)) + ir::Type::iptr())) : addressOperand(p); } ir::Value* machineIpValue(unsigned logicalIp) { - return c->promiseConstant(machineIp(logicalIp), types.address); + return c->promiseConstant(machineIp(logicalIp), ir::Type::iptr()); } unsigned duplicatedIp(unsigned bytecodeIp) @@ -1551,10 +1546,10 @@ class Frame { } void pushObject() { - c->pushed(types.object); + c->pushed(ir::Type::object()); assert(t, sp + 1 <= frameSize()); - set(sp++, types.object); + set(sp++, ir::Type::object()); } void pushLarge(ir::Type type, ir::Value* o) @@ -1566,7 +1561,8 @@ class Frame { set(sp++, type); } - void pop(unsigned count) { + void popFootprint(unsigned count) + { popped(count); c->popped(count); } @@ -1576,7 +1572,7 @@ class Frame { assert(t, sp >= 1); assert(t, sp - 1 >= localSize()); assert(t, get(sp - 1) == type); - set(--sp, types.i4); + set(--sp, ir::Type::i4()); return c->pop(type); } @@ -1603,7 +1599,9 @@ class Frame { void store(ir::Type type, unsigned index) { - assert(t, type == types.i4 || type == types.f4 || type == types.object); + assert(t, + type == ir::Type::i4() || type == ir::Type::f4() + || type == ir::Type::object()); storeLocal(context, 1, type, pop(type), index); unsigned ti = translateLocalIndex(context, 1, index); assert(t, ti < localSize()); @@ -1619,7 +1617,7 @@ class Frame { } void dup() { - c->push(types.i4, c->peek(1, 0)); + c->push(ir::Type::i4(), c->peek(1, 0)); assert(t, sp + 1 <= frameSize()); assert(t, sp - 1 >= localSize()); @@ -1628,12 +1626,12 @@ class Frame { } void dupX1() { - ir::Value* s0 = c->pop(types.i4); - ir::Value* s1 = c->pop(types.i4); + ir::Value* s0 = c->pop(ir::Type::i4()); + ir::Value* s1 = c->pop(ir::Type::i4()); - c->push(types.i4, s0); - c->push(types.i4, s1); - c->push(types.i4, s0); + c->push(ir::Type::i4(), s0); + c->push(ir::Type::i4(), s1); + c->push(ir::Type::i4(), s0); assert(t, sp + 1 <= frameSize()); assert(t, sp - 2 >= localSize()); @@ -1649,22 +1647,22 @@ class Frame { } void dupX2() { - ir::Value* s0 = c->pop(types.i4); + ir::Value* s0 = c->pop(ir::Type::i4()); - if (get(sp - 2) == types.i8) { - ir::Value* s1 = c->pop(types.i8); + if (get(sp - 2) == ir::Type::i8()) { + ir::Value* s1 = c->pop(ir::Type::i8()); - c->push(types.i4, s0); - c->push(types.i8, s1); - c->push(types.i4, s0); + c->push(ir::Type::i4(), s0); + c->push(ir::Type::i8(), s1); + c->push(ir::Type::i4(), s0); } else { - ir::Value* s1 = c->pop(types.i4); - ir::Value* s2 = c->pop(types.i4); + ir::Value* s1 = c->pop(ir::Type::i4()); + ir::Value* s2 = c->pop(ir::Type::i4()); - c->push(types.i4, s0); - c->push(types.i4, s2); - c->push(types.i4, s1); - c->push(types.i4, s0); + c->push(ir::Type::i4(), s0); + c->push(ir::Type::i4(), s2); + c->push(ir::Type::i4(), s1); + c->push(ir::Type::i4(), s0); } assert(t, sp + 1 <= frameSize()); @@ -1683,16 +1681,16 @@ class Frame { } void dup2() { - if (get(sp - 1) == types.i8) { - c->push(types.i8, c->peek(2, 0)); + if (get(sp - 1) == ir::Type::i8()) { + c->push(ir::Type::i8(), c->peek(2, 0)); } else { - ir::Value* s0 = c->pop(types.i4); - ir::Value* s1 = c->pop(types.i4); + ir::Value* s0 = c->pop(ir::Type::i4()); + ir::Value* s1 = c->pop(ir::Type::i4()); - c->push(types.i4, s1); - c->push(types.i4, s0); - c->push(types.i4, s1); - c->push(types.i4, s0); + c->push(ir::Type::i4(), s1); + c->push(ir::Type::i4(), s0); + c->push(ir::Type::i4(), s1); + c->push(ir::Type::i4(), s0); } assert(t, sp + 2 <= frameSize()); @@ -1708,23 +1706,23 @@ class Frame { } void dup2X1() { - if (get(sp - 1) == types.i8) { - ir::Value* s0 = c->pop(types.i8); - ir::Value* s1 = c->pop(types.i4); + if (get(sp - 1) == ir::Type::i8()) { + ir::Value* s0 = c->pop(ir::Type::i8()); + ir::Value* s1 = c->pop(ir::Type::i4()); - c->push(types.i8, s0); - c->push(types.i4, s1); - c->push(types.i8, s0); + c->push(ir::Type::i8(), s0); + c->push(ir::Type::i4(), s1); + c->push(ir::Type::i8(), s0); } else { - ir::Value* s0 = c->pop(types.i4); - ir::Value* s1 = c->pop(types.i4); - ir::Value* s2 = c->pop(types.i4); + ir::Value* s0 = c->pop(ir::Type::i4()); + ir::Value* s1 = c->pop(ir::Type::i4()); + ir::Value* s2 = c->pop(ir::Type::i4()); - c->push(types.i4, s1); - c->push(types.i4, s0); - c->push(types.i4, s2); - c->push(types.i4, s1); - c->push(types.i4, s0); + c->push(ir::Type::i4(), s1); + c->push(ir::Type::i4(), s0); + c->push(ir::Type::i4(), s2); + c->push(ir::Type::i4(), s1); + c->push(ir::Type::i4(), s0); } assert(t, sp + 2 <= frameSize()); @@ -1744,36 +1742,36 @@ class Frame { } void dup2X2() { - if (get(sp - 1) == types.i8) { - ir::Value* s0 = c->pop(types.i8); + if (get(sp - 1) == ir::Type::i8()) { + ir::Value* s0 = c->pop(ir::Type::i8()); - if (get(sp - 3) == types.i8) { - ir::Value* s1 = c->pop(types.i8); + if (get(sp - 3) == ir::Type::i8()) { + ir::Value* s1 = c->pop(ir::Type::i8()); - c->push(types.i8, s0); - c->push(types.i8, s1); - c->push(types.i8, s0); + c->push(ir::Type::i8(), s0); + c->push(ir::Type::i8(), s1); + c->push(ir::Type::i8(), s0); } else { - ir::Value* s1 = c->pop(types.i4); - ir::Value* s2 = c->pop(types.i4); + ir::Value* s1 = c->pop(ir::Type::i4()); + ir::Value* s2 = c->pop(ir::Type::i4()); - c->push(types.i8, s0); - c->push(types.i4, s2); - c->push(types.i4, s1); - c->push(types.i8, s0); + c->push(ir::Type::i8(), s0); + c->push(ir::Type::i4(), s2); + c->push(ir::Type::i4(), s1); + c->push(ir::Type::i8(), s0); } } else { - ir::Value* s0 = c->pop(types.i4); - ir::Value* s1 = c->pop(types.i4); - ir::Value* s2 = c->pop(types.i4); - ir::Value* s3 = c->pop(types.i4); + ir::Value* s0 = c->pop(ir::Type::i4()); + ir::Value* s1 = c->pop(ir::Type::i4()); + ir::Value* s2 = c->pop(ir::Type::i4()); + ir::Value* s3 = c->pop(ir::Type::i4()); - c->push(types.i4, s1); - c->push(types.i4, s0); - c->push(types.i4, s3); - c->push(types.i4, s2); - c->push(types.i4, s1); - c->push(types.i4, s0); + c->push(ir::Type::i4(), s1); + c->push(ir::Type::i4(), s0); + c->push(ir::Type::i4(), s3); + c->push(ir::Type::i4(), s2); + c->push(ir::Type::i4(), s1); + c->push(ir::Type::i4(), s0); } assert(t, sp + 2 <= frameSize()); @@ -1795,11 +1793,11 @@ class Frame { } void swap() { - ir::Value* s0 = c->pop(types.i4); - ir::Value* s1 = c->pop(types.i4); + ir::Value* s0 = c->pop(ir::Type::i4()); + ir::Value* s1 = c->pop(ir::Type::i4()); - c->push(types.i4, s0); - c->push(types.i4, s1); + c->push(ir::Type::i4(), s0); + c->push(ir::Type::i4(), s1); assert(t, sp - 2 >= localSize()); @@ -1837,17 +1835,17 @@ class Frame { case CharField: case ShortField: case IntField: - return push(types.i4, result); + return push(ir::Type::i4(), result); case FloatField: - return push(types.f4, result); + return push(ir::Type::f4(), result); case ObjectField: - return push(types.object, result); + return push(ir::Type::object(), result); case LongField: - return pushLarge(types.i8, result); + return pushLarge(ir::Type::i8(), result); case DoubleField: - return pushLarge(types.f8, result); + return pushLarge(ir::Type::f8(), result); default: abort(t); @@ -1878,7 +1876,7 @@ class Frame { operandTypeForFieldCode(t, returnCode), peekMethodArguments(footprint)); - pop(footprint); + popFootprint(footprint); if (returnCode != VoidField) { pushReturnValue(returnCode, result); @@ -1900,7 +1898,7 @@ class Frame { operandTypeForFieldCode(t, returnCode), peekMethodArguments(footprint)); - pop(footprint); + popFootprint(footprint); if (returnCode != VoidField) { pushReturnValue(returnCode, result); @@ -1912,7 +1910,7 @@ class Frame { // Push a dummy value to the stack, representing the return address (which // we don't need, since we're expanding everything statically). // TODO: in the future, push a value that we can track through type checking - push(types.object, c->constant(0, types.object)); + push(ir::Type::object(), c->constant(0, ir::Type::object())); if (DebugInstructions) { fprintf(stderr, "startSubroutine %u %u\n", ip, returnAddress); @@ -1957,7 +1955,6 @@ class Frame { unsigned ip; unsigned sp; unsigned level; - ir::Types types; }; unsigned @@ -3016,24 +3013,23 @@ resultSize(MyThread* t, unsigned code) ir::Value* popField(MyThread* t, Frame* frame, int code) { - ir::Types types(TargetBytesPerWord); switch (code) { case ByteField: case BooleanField: case CharField: case ShortField: case IntField: - return frame->pop(types.i4); + return frame->pop(ir::Type::i4()); case FloatField: - return frame->pop(types.f4); + return frame->pop(ir::Type::f4()); case LongField: - return frame->popLarge(types.i8); + return frame->popLarge(ir::Type::i8()); case DoubleField: - return frame->popLarge(types.f8); + return frame->popLarge(ir::Type::f8()); case ObjectField: - return frame->pop(types.object); + return frame->pop(ir::Type::object()); default: abort(t); } @@ -3054,11 +3050,10 @@ useLongJump(MyThread* t, uintptr_t target) } void compileSafePoint(MyThread* t, Compiler* c, Frame* frame) { - ir::Types types(TargetBytesPerWord); - c->call(c->constant(getThunk(t, idleIfNecessaryThunk), types.address), + c->call(c->constant(getThunk(t, idleIfNecessaryThunk), ir::Type::iptr()), 0, frame->trace(0, 0), - types.void_, + ir::Type::void_(), 1, c->threadRegister()); } @@ -3071,7 +3066,6 @@ void compileDirectInvoke(MyThread* t, avian::codegen::Promise* addressPromise) { avian::codegen::Compiler* c = frame->c; - ir::Types types(TargetBytesPerWord); unsigned flags = (avian::codegen::TailCalls and tailCall ? Compiler::TailJump : 0); unsigned traceFlags; @@ -3099,22 +3093,23 @@ void compileDirectInvoke(MyThread* t, (frame->context->zone.allocate(sizeof(TraceElementPromise))) TraceElementPromise(t->m->system, trace); - frame->stackCall(c->promiseConstant(returnAddressPromise, types.address), - target, - flags, - trace); + frame->stackCall( + c->promiseConstant(returnAddressPromise, ir::Type::iptr()), + target, + flags, + trace); - c->store( - frame->absoluteAddressOperand(returnAddressPromise), - c->memory( - c->threadRegister(), types.address, TARGET_THREAD_TAILADDRESS)); + c->store(frame->absoluteAddressOperand(returnAddressPromise), + c->memory(c->threadRegister(), + ir::Type::iptr(), + TARGET_THREAD_TAILADDRESS)); c->exit(c->constant((methodFlags(t, target) & ACC_NATIVE) ? nativeThunk(t) : defaultThunk(t), - types.address)); + ir::Type::iptr())); } else { - return frame->stackCall(c->constant(defaultThunk(t), types.address), + return frame->stackCall(c->constant(defaultThunk(t), ir::Type::iptr()), target, flags, frame->trace(target, traceFlags)); @@ -3122,8 +3117,8 @@ void compileDirectInvoke(MyThread* t, } else { ir::Value* address = (addressPromise - ? c->promiseConstant(addressPromise, types.address) - : c->constant(methodAddress(t, target), types.address)); + ? c->promiseConstant(addressPromise, ir::Type::iptr()) + : c->constant(methodAddress(t, target), ir::Type::iptr())); frame->stackCall( address, @@ -3143,7 +3138,7 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall) if (emptyMethod(t, target) and (not classNeedsInit(t, methodClass(t, target)))) { - frame->pop(methodParameterFootprint(t, target)); + frame->popFootprint(methodParameterFootprint(t, target)); tailCall = false; } else { BootContext* bc = frame->context->bootContext; @@ -3193,23 +3188,23 @@ compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk, object reference, bool isStatic, bool tailCall) { avian::codegen::Compiler* c = frame->c; - ir::Types types(TargetBytesPerWord); PROTECT(t, reference); object pair = makePair(t, frame->context->method, reference); - compileReferenceInvoke(frame, - c->call(c->constant(getThunk(t, thunk), types.address), - 0, - frame->trace(0, 0), - types.address, - 2, - c->threadRegister(), - frame->append(pair)), - reference, - isStatic, - tailCall); + compileReferenceInvoke( + frame, + c->call(c->constant(getThunk(t, thunk), ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::iptr(), + 2, + c->threadRegister(), + frame->append(pair)), + reference, + isStatic, + tailCall); } void compileAbstractInvoke(Frame* frame, @@ -3226,24 +3221,23 @@ compileDirectAbstractInvoke(MyThread* t, Frame* frame, Thunk thunk, object target, bool tailCall) { avian::codegen::Compiler* c = frame->c; - ir::Types types(TargetBytesPerWord); - compileAbstractInvoke(frame, - c->call(c->constant(getThunk(t, thunk), types.address), - 0, - frame->trace(0, 0), - types.address, - 2, - c->threadRegister(), - frame->append(target)), - target, - tailCall); + compileAbstractInvoke( + frame, + c->call(c->constant(getThunk(t, thunk), ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::iptr(), + 2, + c->threadRegister(), + frame->append(target)), + target, + tailCall); } void handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) { - ir::Types types(TargetBytesPerWord); avian::codegen::Compiler* c = frame->c; object method = frame->context->method; @@ -3255,13 +3249,13 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) lock = frame->append(methodClass(t, method)); } else { lock = loadLocal( - frame->context, 1, frame->types.object, savedTargetIndex(t, method)); + frame->context, 1, ir::Type::object(), savedTargetIndex(t, method)); } - c->call(c->constant(function, types.address), + c->call(c->constant(function, ir::Type::iptr()), 0, frame->trace(0, 0), - types.void_, + ir::Type::void_(), 2, c->threadRegister(), lock); @@ -3271,7 +3265,6 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) void handleEntrance(MyThread* t, Frame* frame) { - ir::Types types(TargetBytesPerWord); object method = frame->context->method; if ((methodFlags(t, method) & (ACC_SYNCHRONIZED | ACC_STATIC)) @@ -3281,10 +3274,10 @@ handleEntrance(MyThread* t, Frame* frame) unsigned index = savedTargetIndex(t, method); storeLocal(frame->context, 1, - frame->types.object, - loadLocal(frame->context, 1, frame->types.object, 0), + ir::Type::object(), + loadLocal(frame->context, 1, ir::Type::object(), 0), index); - frame->set(index, types.object); + frame->set(index, ir::Type::object()); } handleMonitorEvent @@ -3546,17 +3539,16 @@ bool floatBranch(MyThread* t, ir::Value* popLongAddress(Frame* frame) { - ir::Types types(TargetBytesPerWord); return TargetBytesPerWord == 8 - ? frame->popLarge(types.i8) - : frame->c->load( - ir::SignExtend, frame->popLarge(types.i8), types.address); + ? frame->popLarge(ir::Type::i8()) + : frame->c->load(ir::SignExtend, + frame->popLarge(ir::Type::i8()), + ir::Type::iptr()); } bool intrinsic(MyThread* t, Frame* frame, object target) { - ir::Types types(TargetBytesPerWord); #define MATCH(name, constant) \ (byteArrayLength(t, name) == sizeof(constant) \ and ::strcmp(reinterpret_cast(&byteArrayBody(t, name, 0)), \ @@ -3569,20 +3561,22 @@ intrinsic(MyThread* t, Frame* frame, object target) and MATCH(methodSpec(t, target), "(D)D")) { frame->pushLarge( - types.f8, - c->unaryOp(lir::FloatSquareRoot, frame->popLarge(types.f8))); + ir::Type::f8(), + c->unaryOp(lir::FloatSquareRoot, frame->popLarge(ir::Type::f8()))); return true; } else if (MATCH(methodName(t, target), "abs")) { if (MATCH(methodSpec(t, target), "(I)I")) { - frame->push(types.i4, c->unaryOp(lir::Absolute, frame->pop(types.i4))); + frame->push(ir::Type::i4(), + c->unaryOp(lir::Absolute, frame->pop(ir::Type::i4()))); return true; } else if (MATCH(methodSpec(t, target), "(J)J")) { - frame->pushLarge(types.i8, - c->unaryOp(lir::Absolute, frame->popLarge(types.i8))); + frame->pushLarge( + ir::Type::i8(), + c->unaryOp(lir::Absolute, frame->popLarge(ir::Type::i8()))); return true; } else if (MATCH(methodSpec(t, target), "(F)F")) { - frame->push(types.f4, - c->unaryOp(lir::FloatAbsolute, frame->pop(types.f4))); + frame->push(ir::Type::f4(), + c->unaryOp(lir::FloatAbsolute, frame->pop(ir::Type::f4()))); return true; } } @@ -3592,18 +3586,19 @@ intrinsic(MyThread* t, Frame* frame, object target) and MATCH(methodSpec(t, target), "(J)B")) { ir::Value* address = popLongAddress(frame); - frame->pop(types.object); - frame->push( - types.i4, - c->load(ir::SignExtend, c->memory(address, types.i1), types.i4)); + frame->pop(ir::Type::object()); + frame->push(ir::Type::i4(), + c->load(ir::SignExtend, + c->memory(address, ir::Type::i1()), + ir::Type::i4())); return true; } else if (MATCH(methodName(t, target), "putByte") and MATCH(methodSpec(t, target), "(JB)V")) { - ir::Value* value = frame->pop(types.i4); + ir::Value* value = frame->pop(ir::Type::i4()); ir::Value* address = popLongAddress(frame); - frame->pop(types.object); - c->store(value, c->memory(address, types.i1)); + frame->pop(ir::Type::object()); + c->store(value, c->memory(address, ir::Type::i1())); return true; } else if ((MATCH(methodName(t, target), "getShort") and MATCH(methodSpec(t, target), "(J)S")) @@ -3611,20 +3606,21 @@ intrinsic(MyThread* t, Frame* frame, object target) and MATCH(methodSpec(t, target), "(J)C"))) { ir::Value* address = popLongAddress(frame); - frame->pop(types.object); - frame->push( - types.i4, - c->load(ir::SignExtend, c->memory(address, types.i2), types.i4)); + frame->pop(ir::Type::object()); + frame->push(ir::Type::i4(), + c->load(ir::SignExtend, + c->memory(address, ir::Type::i2()), + ir::Type::i4())); return true; } else if ((MATCH(methodName(t, target), "putShort") and MATCH(methodSpec(t, target), "(JS)V")) or (MATCH(methodName(t, target), "putChar") and MATCH(methodSpec(t, target), "(JC)V"))) { - ir::Value* value = frame->pop(types.i4); + ir::Value* value = frame->pop(ir::Type::i4()); ir::Value* address = popLongAddress(frame); - frame->pop(types.object); - c->store(value, c->memory(address, types.i2)); + frame->pop(ir::Type::object()); + c->store(value, c->memory(address, ir::Type::i2())); return true; } else if ((MATCH(methodName(t, target), "getInt") and MATCH(methodSpec(t, target), "(J)I")) @@ -3632,9 +3628,9 @@ intrinsic(MyThread* t, Frame* frame, object target) and MATCH(methodSpec(t, target), "(J)F"))) { ir::Value* address = popLongAddress(frame); - frame->pop(types.object); - ir::Type type = MATCH(methodName(t, target), "getInt") ? types.i4 - : types.f4; + frame->pop(ir::Type::object()); + ir::Type type = MATCH(methodName(t, target), "getInt") ? ir::Type::i4() + : ir::Type::f4(); frame->push(type, c->load(ir::SignExtend, c->memory(address, type), type)); return true; @@ -3643,11 +3639,11 @@ intrinsic(MyThread* t, Frame* frame, object target) or (MATCH(methodName(t, target), "putFloat") and MATCH(methodSpec(t, target), "(JF)V"))) { - ir::Type type = MATCH(methodName(t, target), "putInt") ? types.i4 - : types.f4; + ir::Type type = MATCH(methodName(t, target), "putInt") ? ir::Type::i4() + : ir::Type::f4(); ir::Value* value = frame->pop(type); ir::Value* address = popLongAddress(frame); - frame->pop(types.object); + frame->pop(ir::Type::object()); c->store(value, c->memory(address, type)); return true; } else if ((MATCH(methodName(t, target), "getLong") @@ -3656,9 +3652,9 @@ intrinsic(MyThread* t, Frame* frame, object target) and MATCH(methodSpec(t, target), "(J)D"))) { ir::Value* address = popLongAddress(frame); - frame->pop(types.object); - ir::Type type = MATCH(methodName(t, target), "getLong") ? types.i8 - : types.f8; + frame->pop(ir::Type::object()); + ir::Type type = MATCH(methodName(t, target), "getLong") ? ir::Type::i8() + : ir::Type::f8(); frame->pushLarge(type, c->load(ir::SignExtend, c->memory(address, type), type)); return true; @@ -3667,29 +3663,30 @@ intrinsic(MyThread* t, Frame* frame, object target) or (MATCH(methodName(t, target), "putDouble") and MATCH(methodSpec(t, target), "(JD)V"))) { - ir::Type type = MATCH(methodName(t, target), "putLong") ? types.i8 - : types.f8; + ir::Type type = MATCH(methodName(t, target), "putLong") ? ir::Type::i8() + : ir::Type::f8(); ir::Value* value = frame->popLarge(type); ir::Value* address = popLongAddress(frame); - frame->pop(types.object); + frame->pop(ir::Type::object()); c->store(value, c->memory(address, type)); return true; } else if (MATCH(methodName(t, target), "getAddress") and MATCH(methodSpec(t, target), "(J)J")) { ir::Value* address = popLongAddress(frame); - frame->pop(types.object); - frame->pushLarge( - types.i8, - c->load(ir::SignExtend, c->memory(address, types.address), types.i8)); + frame->pop(ir::Type::object()); + frame->pushLarge(ir::Type::i8(), + c->load(ir::SignExtend, + c->memory(address, ir::Type::iptr()), + ir::Type::i8())); return true; } else if (MATCH(methodName(t, target), "putAddress") and MATCH(methodSpec(t, target), "(JJ)V")) { - ir::Value* value = frame->popLarge(types.i8); + ir::Value* value = frame->popLarge(ir::Type::i8()); ir::Value* address = popLongAddress(frame); - frame->pop(types.object); - c->store(value, c->memory(address, types.address)); + frame->pop(ir::Type::object()); + c->store(value, c->memory(address, ir::Type::iptr())); return true; } } @@ -3871,7 +3868,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, unsigned newIp; stack.pushValue(Return); - ir::Types types(TargetBytesPerWord); start: ir::Type* stackMap @@ -3898,10 +3894,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushObject(); - c->call(c->constant(getThunk(t, gcIfNecessaryThunk), types.address), + c->call(c->constant(getThunk(t, gcIfNecessaryThunk), ir::Type::iptr()), 0, frame->trace(0, 0), - types.void_, + ir::Type::void_(), 1, c->threadRegister()); } @@ -3913,15 +3909,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, fprintf(stderr, " stack: ["); for (size_t i = frame->localSize(); i < frame->sp; i++) { ir::Type ty = frame->get(i); - if (ty == types.i4) { + if (ty == ir::Type::i4()) { fprintf(stderr, "I"); - } else if (ty == types.i8) { + } else if (ty == ir::Type::i8()) { fprintf(stderr, "L"); - } else if (ty == types.f4) { + } else if (ty == ir::Type::f4()) { fprintf(stderr, "F"); - } else if (ty == types.f8) { + } else if (ty == ir::Type::f8()) { fprintf(stderr, "D"); - } else if (ty == types.object) { + } else if (ty == ir::Type::object()) { fprintf(stderr, "O"); } else { fprintf(stderr, "?"); @@ -3944,8 +3940,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case iaload: case laload: case saload: { - ir::Value* index = frame->pop(types.i4); - ir::Value* array = frame->pop(types.object); + ir::Value* index = frame->pop(ir::Type::i4()); + ir::Value* array = frame->pop(ir::Type::object()); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); @@ -3959,61 +3955,67 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (instruction) { case aaload: frame->push( - types.object, - c->load(ir::SignExtend, - c->memory(array, types.object, TargetArrayBody, index), - types.object)); + ir::Type::object(), + c->load( + ir::SignExtend, + c->memory(array, ir::Type::object(), TargetArrayBody, index), + ir::Type::object())); break; case faload: - frame->push(types.f4, - c->load(ir::SignExtend, - c->memory(array, types.f4, TargetArrayBody, index), - types.f4)); + frame->push( + ir::Type::f4(), + c->load(ir::SignExtend, + c->memory(array, ir::Type::f4(), TargetArrayBody, index), + ir::Type::f4())); break; case iaload: - frame->push(types.i4, - c->load(ir::SignExtend, - c->memory(array, types.i4, TargetArrayBody, index), - types.i4)); + frame->push( + ir::Type::i4(), + c->load(ir::SignExtend, + c->memory(array, ir::Type::i4(), TargetArrayBody, index), + ir::Type::i4())); break; case baload: - frame->push(types.i4, - c->load(ir::SignExtend, - c->memory(array, types.i1, TargetArrayBody, index), - types.i4)); + frame->push( + ir::Type::i4(), + c->load(ir::SignExtend, + c->memory(array, ir::Type::i1(), TargetArrayBody, index), + ir::Type::i4())); break; case caload: - frame->push(types.i4, - c->load(ir::ZeroExtend, - c->memory(array, types.i2, TargetArrayBody, index), - types.i4)); + frame->push( + ir::Type::i4(), + c->load(ir::ZeroExtend, + c->memory(array, ir::Type::i2(), TargetArrayBody, index), + ir::Type::i4())); break; case daload: frame->pushLarge( - types.f8, + ir::Type::f8(), c->load(ir::SignExtend, - c->memory(array, types.f8, TargetArrayBody, index), - types.f8)); + c->memory(array, ir::Type::f8(), TargetArrayBody, index), + ir::Type::f8())); break; case laload: frame->pushLarge( - types.i8, + ir::Type::i8(), c->load(ir::SignExtend, - c->memory(array, types.i8, TargetArrayBody, index), - types.i8)); + c->memory(array, ir::Type::i8(), TargetArrayBody, index), + ir::Type::i8())); break; case saload: - frame->push(types.i4, - c->load(ir::SignExtend, - c->memory(array, types.i2, TargetArrayBody, index), - types.i4)); + frame->push( + ir::Type::i4(), + c->load(ir::SignExtend, + c->memory(array, ir::Type::i2(), TargetArrayBody, index), + ir::Type::i4())); break; } } break; @@ -4028,19 +4030,19 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case sastore: { ir::Value* value; if (instruction == lastore) { - value = frame->popLarge(types.i8); + value = frame->popLarge(ir::Type::i8()); } else if (instruction == dastore) { - value = frame->popLarge(types.f8); + value = frame->popLarge(ir::Type::f8()); } else if (instruction == aastore) { - value = frame->pop(types.object); + value = frame->pop(ir::Type::object()); } else if (instruction == fastore) { - value = frame->pop(types.f4); + value = frame->pop(ir::Type::f4()); } else { - value = frame->pop(types.i4); + value = frame->pop(ir::Type::i4()); } - ir::Value* index = frame->pop(types.i4); - ir::Value* array = frame->pop(types.object); + ir::Value* index = frame->pop(ir::Type::i4()); + ir::Value* array = frame->pop(ir::Type::object()); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); @@ -4053,73 +4055,79 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (instruction) { case aastore: { - c->call(c->constant(getThunk(t, setMaybeNullThunk), types.address), + c->call(c->constant(getThunk(t, setMaybeNullThunk), ir::Type::iptr()), 0, frame->trace(0, 0), - types.void_, + ir::Type::void_(), 4, c->threadRegister(), array, - c->binaryOp( - lir::Add, - types.i4, - c->constant(TargetArrayBody, types.i4), - c->binaryOp(lir::ShiftLeft, - types.i4, - c->constant(log(TargetBytesPerWord), types.i4), - index)), + c->binaryOp(lir::Add, + ir::Type::i4(), + c->constant(TargetArrayBody, ir::Type::i4()), + c->binaryOp(lir::ShiftLeft, + ir::Type::i4(), + c->constant(log(TargetBytesPerWord), + ir::Type::i4()), + index)), value); } break; case fastore: - c->store(value, c->memory(array, types.f4, TargetArrayBody, index)); + c->store(value, + c->memory(array, ir::Type::f4(), TargetArrayBody, index)); break; case iastore: - c->store(value, c->memory(array, types.i4, TargetArrayBody, index)); + c->store(value, + c->memory(array, ir::Type::i4(), TargetArrayBody, index)); break; case bastore: - c->store(value, c->memory(array, types.i1, TargetArrayBody, index)); + c->store(value, + c->memory(array, ir::Type::i1(), TargetArrayBody, index)); break; case castore: case sastore: - c->store(value, c->memory(array, types.i2, TargetArrayBody, index)); + c->store(value, + c->memory(array, ir::Type::i2(), TargetArrayBody, index)); break; case dastore: - c->store(value, c->memory(array, types.f8, TargetArrayBody, index)); + c->store(value, + c->memory(array, ir::Type::f8(), TargetArrayBody, index)); break; case lastore: - c->store(value, c->memory(array, types.i8, TargetArrayBody, index)); + c->store(value, + c->memory(array, ir::Type::i8(), TargetArrayBody, index)); break; } } break; case aconst_null: - frame->push(types.object, c->constant(0, types.object)); + frame->push(ir::Type::object(), c->constant(0, ir::Type::object())); break; case aload: - frame->load(types.object, codeBody(t, code, ip++)); + frame->load(ir::Type::object(), codeBody(t, code, ip++)); break; case aload_0: - frame->load(types.object, 0); + frame->load(ir::Type::object(), 0); break; case aload_1: - frame->load(types.object, 1); + frame->load(ir::Type::object(), 1); break; case aload_2: - frame->load(types.object, 2); + frame->load(ir::Type::object(), 2); break; case aload_3: - frame->load(types.object, 3); + frame->load(ir::Type::object(), 3); break; case anewarray: { @@ -4132,7 +4140,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, object class_ = resolveClassInPool(t, context->method, index - 1, false); - ir::Value* length = frame->pop(types.i4); + ir::Value* length = frame->pop(ir::Type::i4()); object argument; Thunk thunk; @@ -4144,11 +4152,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, thunk = makeBlankObjectArrayFromReferenceThunk; } - frame->push(types.object, - c->call(c->constant(getThunk(t, thunk), types.address), + frame->push(ir::Type::object(), + c->call(c->constant(getThunk(t, thunk), ir::Type::iptr()), 0, frame->trace(0, 0), - types.object, + ir::Type::object(), 3, c->threadRegister(), frame->append(argument), @@ -4157,44 +4165,44 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case areturn: { handleExit(t, frame); - c->return_(frame->pop(types.object)); + c->return_(frame->pop(ir::Type::object())); } goto next; case arraylength: { - frame->push(types.i4, + frame->push(ir::Type::i4(), c->load(ir::SignExtend, - c->memory(frame->pop(types.object), - types.address, + c->memory(frame->pop(ir::Type::object()), + ir::Type::iptr(), TargetArrayLength), - types.i4)); + ir::Type::i4())); } break; case astore: - frame->store(types.object, codeBody(t, code, ip++)); + frame->store(ir::Type::object(), codeBody(t, code, ip++)); break; case astore_0: - frame->store(types.object, 0); + frame->store(ir::Type::object(), 0); break; case astore_1: - frame->store(types.object, 1); + frame->store(ir::Type::object(), 1); break; case astore_2: - frame->store(types.object, 2); + frame->store(ir::Type::object(), 2); break; case astore_3: - frame->store(types.object, 3); + frame->store(ir::Type::object(), 3); break; case athrow: { - ir::Value* target = frame->pop(types.object); - c->call(c->constant(getThunk(t, throw_Thunk), types.address), + ir::Value* target = frame->pop(ir::Type::object()); + c->call(c->constant(getThunk(t, throw_Thunk), ir::Type::iptr()), Compiler::NoReturn, frame->trace(0, 0), - types.void_, + ir::Type::void_(), 2, c->threadRegister(), target); @@ -4203,9 +4211,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } goto next; case bipush: - frame->push( - types.i4, - c->constant(static_cast(codeBody(t, code, ip++)), types.i4)); + frame->push(ir::Type::i4(), + c->constant(static_cast(codeBody(t, code, ip++)), + ir::Type::i4())); break; case checkcast: { @@ -4230,10 +4238,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* instance = c->peek(1, 0); - c->call(c->constant(getThunk(t, thunk), types.address), + c->call(c->constant(getThunk(t, thunk), ir::Type::iptr()), 0, frame->trace(0, 0), - types.void_, + ir::Type::void_(), 3, c->threadRegister(), frame->append(argument), @@ -4241,15 +4249,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case d2f: { - frame->push(types.f4, c->f2f(types.f4, frame->popLarge(types.f8))); + frame->push(ir::Type::f4(), + c->f2f(ir::Type::f4(), frame->popLarge(ir::Type::f8()))); } break; case d2i: { - frame->push(types.i4, c->f2i(types.i4, frame->popLarge(types.f8))); + frame->push(ir::Type::i4(), + c->f2i(ir::Type::i4(), frame->popLarge(ir::Type::f8()))); } break; case d2l: { - frame->pushLarge(types.i8, c->f2i(types.i8, frame->popLarge(types.f8))); + frame->pushLarge(ir::Type::i8(), + c->f2i(ir::Type::i8(), frame->popLarge(ir::Type::f8()))); } break; case dadd: @@ -4257,27 +4268,28 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case dmul: case ddiv: case vm::drem: { - ir::Value* a = frame->popLarge(types.f8); - ir::Value* b = frame->popLarge(types.f8); + ir::Value* a = frame->popLarge(ir::Type::f8()); + ir::Value* b = frame->popLarge(ir::Type::f8()); frame->pushLarge( - types.f8, - c->binaryOp(toCompilerBinaryOp(t, instruction), types.f8, a, b)); + ir::Type::f8(), + c->binaryOp( + toCompilerBinaryOp(t, instruction), ir::Type::f8(), a, b)); } break; case dcmpg: { - ir::Value* a = frame->popLarge(types.f8); - ir::Value* b = frame->popLarge(types.f8); + ir::Value* a = frame->popLarge(ir::Type::f8()); + ir::Value* b = frame->popLarge(ir::Type::f8()); if (floatBranch(t, frame, code, ip, false, a, b, &newIp)) { goto branch; } else { - frame->push(types.i4, + frame->push(ir::Type::i4(), c->call(c->constant(getThunk(t, compareDoublesGThunk), - types.address), + ir::Type::iptr()), 0, 0, - types.i4, + ir::Type::i4(), 4, static_cast(0), a, @@ -4287,18 +4299,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case dcmpl: { - ir::Value* a = frame->popLarge(types.f8); - ir::Value* b = frame->popLarge(types.f8); + ir::Value* a = frame->popLarge(ir::Type::f8()); + ir::Value* b = frame->popLarge(ir::Type::f8()); if (floatBranch(t, frame, code, ip, true, a, b, &newIp)) { goto branch; } else { - frame->push(types.i4, + frame->push(ir::Type::i4(), c->call(c->constant(getThunk(t, compareDoublesLThunk), - types.address), + ir::Type::iptr()), 0, 0, - types.i4, + ir::Type::i4(), 4, static_cast(0), a, @@ -4308,16 +4320,19 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case dconst_0: - frame->pushLarge(types.f8, c->constant(doubleToBits(0.0), types.f8)); + frame->pushLarge(ir::Type::f8(), + c->constant(doubleToBits(0.0), ir::Type::f8())); break; case dconst_1: - frame->pushLarge(types.f8, c->constant(doubleToBits(1.0), types.f8)); + frame->pushLarge(ir::Type::f8(), + c->constant(doubleToBits(1.0), ir::Type::f8())); break; case dneg: { - frame->pushLarge(types.f8, - c->unaryOp(lir::FloatNegate, frame->popLarge(types.f8))); + frame->pushLarge( + ir::Type::f8(), + c->unaryOp(lir::FloatNegate, frame->popLarge(ir::Type::f8()))); } break; case dup: @@ -4345,15 +4360,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case f2d: { - frame->pushLarge(types.f8, c->f2f(types.f8, frame->pop(types.f4))); + frame->pushLarge(ir::Type::f8(), + c->f2f(ir::Type::f8(), frame->pop(ir::Type::f4()))); } break; case f2i: { - frame->push(types.i4, c->f2i(types.i4, frame->pop(types.f4))); + frame->push(ir::Type::i4(), + c->f2i(ir::Type::i4(), frame->pop(ir::Type::f4()))); } break; case f2l: { - frame->pushLarge(types.i8, c->f2i(types.i8, frame->pop(types.f4))); + frame->pushLarge(ir::Type::i8(), + c->f2i(ir::Type::i8(), frame->pop(ir::Type::f4()))); } break; case fadd: @@ -4361,27 +4379,28 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case fmul: case fdiv: case frem: { - ir::Value* a = frame->pop(types.f4); - ir::Value* b = frame->pop(types.f4); + ir::Value* a = frame->pop(ir::Type::f4()); + ir::Value* b = frame->pop(ir::Type::f4()); frame->push( - types.f4, - c->binaryOp(toCompilerBinaryOp(t, instruction), types.f4, a, b)); + ir::Type::f4(), + c->binaryOp( + toCompilerBinaryOp(t, instruction), ir::Type::f4(), a, b)); } break; case fcmpg: { - ir::Value* a = frame->pop(types.f4); - ir::Value* b = frame->pop(types.f4); + ir::Value* a = frame->pop(ir::Type::f4()); + ir::Value* b = frame->pop(ir::Type::f4()); if (floatBranch(t, frame, code, ip, false, a, b, &newIp)) { goto branch; } else { - frame->push(types.i4, + frame->push(ir::Type::i4(), c->call(c->constant(getThunk(t, compareFloatsGThunk), - types.address), + ir::Type::iptr()), 0, 0, - types.i4, + ir::Type::i4(), 2, a, b)); @@ -4389,18 +4408,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case fcmpl: { - ir::Value* a = frame->pop(types.f4); - ir::Value* b = frame->pop(types.f4); + ir::Value* a = frame->pop(ir::Type::f4()); + ir::Value* b = frame->pop(ir::Type::f4()); if (floatBranch(t, frame, code, ip, true, a, b, &newIp)) { goto branch; } else { - frame->push(types.i4, + frame->push(ir::Type::i4(), c->call(c->constant(getThunk(t, compareFloatsLThunk), - types.address), + ir::Type::iptr()), 0, 0, - types.i4, + ir::Type::i4(), 2, a, b)); @@ -4408,19 +4427,23 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case fconst_0: - frame->push(types.f4, c->constant(floatToBits(0.0), types.f4)); + frame->push(ir::Type::f4(), + c->constant(floatToBits(0.0), ir::Type::f4())); break; case fconst_1: - frame->push(types.f4, c->constant(floatToBits(1.0), types.f4)); + frame->push(ir::Type::f4(), + c->constant(floatToBits(1.0), ir::Type::f4())); break; case fconst_2: - frame->push(types.f4, c->constant(floatToBits(2.0), types.f4)); + frame->push(ir::Type::f4(), + c->constant(floatToBits(2.0), ir::Type::f4())); break; case fneg: { - frame->push(types.f4, c->unaryOp(lir::FloatNegate, frame->pop(types.f4))); + frame->push(ir::Type::f4(), + c->unaryOp(lir::FloatNegate, frame->pop(ir::Type::f4()))); } break; case getfield: @@ -4443,10 +4466,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, PROTECT(t, field); c->call(c->constant(getThunk(t, acquireMonitorForObjectThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), - types.void_, + ir::Type::void_(), 2, c->threadRegister(), frame->append(field)); @@ -4460,20 +4483,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, PROTECT(t, field); if (classNeedsInit(t, fieldClass(t, field))) { - c->call(c->constant(getThunk(t, tryInitClassThunk), types.address), - 0, - frame->trace(0, 0), - types.void_, - 2, - c->threadRegister(), - frame->append(fieldClass(t, field))); + c->call( + c->constant(getThunk(t, tryInitClassThunk), ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::void_(), + 2, + c->threadRegister(), + frame->append(fieldClass(t, field))); } table = frame->append(classStaticTable(t, fieldClass(t, field))); } else { checkField(t, field, false); - table = frame->pop(types.object); + table = frame->pop(ir::Type::object()); if (inTryBlock(t, code, ip - 3)) { c->saveLocals(); @@ -4484,75 +4508,75 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, switch (fieldCode(t, field)) { case ByteField: case BooleanField: - frame->push( - types.i4, - c->load( - ir::SignExtend, - c->memory(table, types.i1, targetFieldOffset(context, field)), - types.i4)); + frame->push(ir::Type::i4(), + c->load(ir::SignExtend, + c->memory(table, + ir::Type::i1(), + targetFieldOffset(context, field)), + ir::Type::i4())); break; case CharField: - frame->push( - types.i4, - c->load( - ir::ZeroExtend, - c->memory(table, types.i2, targetFieldOffset(context, field)), - types.i4)); + frame->push(ir::Type::i4(), + c->load(ir::ZeroExtend, + c->memory(table, + ir::Type::i2(), + targetFieldOffset(context, field)), + ir::Type::i4())); break; case ShortField: - frame->push( - types.i4, - c->load( - ir::SignExtend, - c->memory(table, types.i2, targetFieldOffset(context, field)), - types.i4)); + frame->push(ir::Type::i4(), + c->load(ir::SignExtend, + c->memory(table, + ir::Type::i2(), + targetFieldOffset(context, field)), + ir::Type::i4())); break; case FloatField: - frame->push( - types.f4, - c->load( - ir::SignExtend, - c->memory(table, types.f4, targetFieldOffset(context, field)), - types.f4)); + frame->push(ir::Type::f4(), + c->load(ir::SignExtend, + c->memory(table, + ir::Type::f4(), + targetFieldOffset(context, field)), + ir::Type::f4())); break; case IntField: - frame->push( - types.i4, - c->load( - ir::SignExtend, - c->memory(table, types.i4, targetFieldOffset(context, field)), - types.i4)); + frame->push(ir::Type::i4(), + c->load(ir::SignExtend, + c->memory(table, + ir::Type::i4(), + targetFieldOffset(context, field)), + ir::Type::i4())); break; case DoubleField: - frame->pushLarge( - types.f8, - c->load( - ir::SignExtend, - c->memory(table, types.f8, targetFieldOffset(context, field)), - types.f8)); + frame->pushLarge(ir::Type::f8(), + c->load(ir::SignExtend, + c->memory(table, + ir::Type::f8(), + targetFieldOffset(context, field)), + ir::Type::f8())); break; case LongField: - frame->pushLarge( - types.i8, - c->load( - ir::SignExtend, - c->memory(table, types.i8, targetFieldOffset(context, field)), - types.i8)); + frame->pushLarge(ir::Type::i8(), + c->load(ir::SignExtend, + c->memory(table, + ir::Type::i8(), + targetFieldOffset(context, field)), + ir::Type::i8())); break; case ObjectField: - frame->push(types.object, + frame->push(ir::Type::object(), c->load(ir::SignExtend, c->memory(table, - types.object, + ir::Type::object(), targetFieldOffset(context, field)), - types.object)); + ir::Type::object())); break; default: @@ -4565,10 +4589,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, or fieldCode(t, field) == LongField)) { c->call(c->constant(getThunk(t, releaseMonitorForObjectThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), - types.void_, + ir::Type::void_(), 2, c->threadRegister(), frame->append(field)); @@ -4588,7 +4612,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (instruction == getstatic) { result = c->call( c->constant(getThunk(t, getStaticFieldValueFromReferenceThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), rType, @@ -4596,11 +4620,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->threadRegister(), frame->append(pair)); } else { - ir::Value* instance = frame->pop(types.object); + ir::Value* instance = frame->pop(ir::Type::object()); result = c->call( c->constant(getThunk(t, getFieldValueFromReferenceThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), rType, @@ -4641,39 +4665,45 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case i2b: { - frame->push( - types.i4, - c->truncateThenExtend( - ir::SignExtend, types.i4, types.i1, frame->pop(types.i4))); + frame->push(ir::Type::i4(), + c->truncateThenExtend(ir::SignExtend, + ir::Type::i4(), + ir::Type::i1(), + frame->pop(ir::Type::i4()))); } break; case i2c: { - frame->push( - types.i4, - c->truncateThenExtend( - ir::ZeroExtend, types.i4, types.i2, frame->pop(types.i4))); + frame->push(ir::Type::i4(), + c->truncateThenExtend(ir::ZeroExtend, + ir::Type::i4(), + ir::Type::i2(), + frame->pop(ir::Type::i4()))); } break; case i2d: { - frame->pushLarge(types.f8, c->i2f(types.f8, frame->pop(types.i4))); + frame->pushLarge(ir::Type::f8(), + c->i2f(ir::Type::f8(), frame->pop(ir::Type::i4()))); } break; case i2f: { - frame->push(types.f4, c->i2f(types.f4, frame->pop(types.i4))); + frame->push(ir::Type::f4(), + c->i2f(ir::Type::f4(), frame->pop(ir::Type::i4()))); } break; case i2l: - frame->pushLarge( - types.i8, - c->truncateThenExtend( - ir::SignExtend, types.i8, types.i4, frame->pop(types.i4))); + frame->pushLarge(ir::Type::i8(), + c->truncateThenExtend(ir::SignExtend, + ir::Type::i8(), + ir::Type::i4(), + frame->pop(ir::Type::i4()))); break; case i2s: { - frame->push( - types.i4, - c->truncateThenExtend( - ir::SignExtend, types.i4, types.i2, frame->pop(types.i4))); + frame->push(ir::Type::i4(), + c->truncateThenExtend(ir::SignExtend, + ir::Type::i4(), + ir::Type::i2(), + frame->pop(ir::Type::i4()))); } break; case iadd: @@ -4685,51 +4715,53 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case isub: case ixor: case imul: { - ir::Value* a = frame->pop(types.i4); - ir::Value* b = frame->pop(types.i4); + ir::Value* a = frame->pop(ir::Type::i4()); + ir::Value* b = frame->pop(ir::Type::i4()); frame->push( - types.i4, - c->binaryOp(toCompilerBinaryOp(t, instruction), types.i4, a, b)); + ir::Type::i4(), + c->binaryOp( + toCompilerBinaryOp(t, instruction), ir::Type::i4(), a, b)); } break; case iconst_m1: - frame->push(types.i4, c->constant(-1, types.i4)); + frame->push(ir::Type::i4(), c->constant(-1, ir::Type::i4())); break; case iconst_0: - frame->push(types.i4, c->constant(0, types.i4)); + frame->push(ir::Type::i4(), c->constant(0, ir::Type::i4())); break; case iconst_1: - frame->push(types.i4, c->constant(1, types.i4)); + frame->push(ir::Type::i4(), c->constant(1, ir::Type::i4())); break; case iconst_2: - frame->push(types.i4, c->constant(2, types.i4)); + frame->push(ir::Type::i4(), c->constant(2, ir::Type::i4())); break; case iconst_3: - frame->push(types.i4, c->constant(3, types.i4)); + frame->push(ir::Type::i4(), c->constant(3, ir::Type::i4())); break; case iconst_4: - frame->push(types.i4, c->constant(4, types.i4)); + frame->push(ir::Type::i4(), c->constant(4, ir::Type::i4())); break; case iconst_5: - frame->push(types.i4, c->constant(5, types.i4)); + frame->push(ir::Type::i4(), c->constant(5, ir::Type::i4())); break; case idiv: { - ir::Value* a = frame->pop(types.i4); - ir::Value* b = frame->pop(types.i4); + ir::Value* a = frame->pop(ir::Type::i4()); + ir::Value* b = frame->pop(ir::Type::i4()); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); frame->trace(0, 0); } - frame->push(types.i4, c->binaryOp(lir::Divide, types.i4, a, b)); + frame->push(ir::Type::i4(), + c->binaryOp(lir::Divide, ir::Type::i4(), a, b)); } break; case if_acmpeq: @@ -4742,8 +4774,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - ir::Value* a = frame->pop(types.object); - ir::Value* b = frame->pop(types.object); + ir::Value* a = frame->pop(ir::Type::object()); + ir::Value* b = frame->pop(ir::Type::object()); ir::Value* target = frame->machineIpValue(newIp); c->condJump(toCompilerJumpOp(t, instruction), a, b, target); @@ -4763,8 +4795,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - ir::Value* a = frame->pop(types.i4); - ir::Value* b = frame->pop(types.i4); + ir::Value* a = frame->pop(ir::Type::i4()); + ir::Value* b = frame->pop(ir::Type::i4()); ir::Value* target = frame->machineIpValue(newIp); c->condJump(toCompilerJumpOp(t, instruction), a, b, target); @@ -4786,8 +4818,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - ir::Value* a = c->constant(0, types.i4); - ir::Value* b = frame->pop(types.i4); + ir::Value* a = c->constant(0, ir::Type::i4()); + ir::Value* b = frame->pop(ir::Type::i4()); c->condJump(toCompilerJumpOp(t, instruction), a, b, target); } goto branch; @@ -4802,8 +4834,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, compileSafePoint(t, c, frame); } - ir::Value* a = c->constant(0, types.object); - ir::Value* b = frame->pop(types.object); + ir::Value* a = c->constant(0, ir::Type::object()); + ir::Value* b = frame->pop(ir::Type::object()); ir::Value* target = frame->machineIpValue(newIp); c->condJump(toCompilerJumpOp(t, instruction), a, b, target); @@ -4815,51 +4847,52 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, storeLocal(context, 1, - types.i4, + ir::Type::i4(), c->binaryOp(lir::Add, - types.i4, - c->constant(count, types.i4), - loadLocal(context, 1, types.i4, index)), + ir::Type::i4(), + c->constant(count, ir::Type::i4()), + loadLocal(context, 1, ir::Type::i4(), index)), index); } break; case iload: - frame->load(types.i4, codeBody(t, code, ip++)); + frame->load(ir::Type::i4(), codeBody(t, code, ip++)); break; case fload: - frame->load(types.f4, codeBody(t, code, ip++)); + frame->load(ir::Type::f4(), codeBody(t, code, ip++)); break; case iload_0: - frame->load(types.i4, 0); + frame->load(ir::Type::i4(), 0); break; case fload_0: - frame->load(types.f4, 0); + frame->load(ir::Type::f4(), 0); break; case iload_1: - frame->load(types.i4, 1); + frame->load(ir::Type::i4(), 1); break; case fload_1: - frame->load(types.f4, 1); + frame->load(ir::Type::f4(), 1); break; case iload_2: - frame->load(types.i4, 2); + frame->load(ir::Type::i4(), 2); break; case fload_2: - frame->load(types.f4, 2); + frame->load(ir::Type::f4(), 2); break; case iload_3: - frame->load(types.i4, 3); + frame->load(ir::Type::i4(), 3); break; case fload_3: - frame->load(types.f4, 3); + frame->load(ir::Type::f4(), 3); break; case ineg: { - frame->push(types.i4, c->unaryOp(lir::Negate, frame->pop(types.i4))); + frame->push(ir::Type::i4(), + c->unaryOp(lir::Negate, frame->pop(ir::Type::i4()))); } break; case instanceof: { @@ -4872,7 +4905,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, object class_ = resolveClassInPool(t, context->method, index - 1, false); - ir::Value* instance = frame->pop(types.object); + ir::Value* instance = frame->pop(ir::Type::object()); object argument; Thunk thunk; @@ -4884,11 +4917,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, thunk = instanceOfFromReferenceThunk; } - frame->push(types.i4, - c->call(c->constant(getThunk(t, thunk), types.address), + frame->push(ir::Type::i4(), + c->call(c->constant(getThunk(t, thunk), ir::Type::iptr()), 0, frame->trace(0, 0), - types.i4, + ir::Type::i4(), 3, c->threadRegister(), frame->append(argument), @@ -4933,21 +4966,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, unsigned rSize = resultSize(t, returnCode); - ir::Value* result - = c->stackCall(c->call(c->constant(getThunk(t, thunk), types.address), - 0, - frame->trace(0, 0), - types.address, - 3, - c->threadRegister(), - frame->append(argument), - c->peek(1, parameterFootprint - 1)), - tailCall ? Compiler::TailJump : 0, - frame->trace(0, 0), - operandTypeForFieldCode(t, returnCode), - frame->peekMethodArguments(parameterFootprint)); + ir::Value* result = c->stackCall( + c->call(c->constant(getThunk(t, thunk), ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::iptr(), + 3, + c->threadRegister(), + frame->append(argument), + c->peek(1, parameterFootprint - 1)), + tailCall ? Compiler::TailJump : 0, + frame->trace(0, 0), + operandTypeForFieldCode(t, returnCode), + frame->peekMethodArguments(parameterFootprint)); - frame->pop(parameterFootprint); + frame->popFootprint(parameterFootprint); if (rSize) { frame->pushReturnValue(returnCode, result); @@ -5042,13 +5075,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* instance = c->peek(1, parameterFootprint - 1); frame->stackCall( - c->memory( - c->binaryOp(lir::And, - types.address, - c->constant(TargetPointerMask, types.address), - c->memory(instance, types.object)), - types.object, - offset), + c->memory(c->binaryOp( + lir::And, + ir::Type::iptr(), + c->constant(TargetPointerMask, ir::Type::iptr()), + c->memory(instance, ir::Type::object())), + ir::Type::object(), + offset), target, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0)); @@ -5069,10 +5102,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame, c->call( c->constant(getThunk(t, findVirtualMethodFromReferenceThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), - types.address, + ir::Type::iptr(), 3, c->threadRegister(), frame->append(pair), @@ -5086,61 +5119,62 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case irem: { - ir::Value* a = frame->pop(types.i4); - ir::Value* b = frame->pop(types.i4); + ir::Value* a = frame->pop(ir::Type::i4()); + ir::Value* b = frame->pop(ir::Type::i4()); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); frame->trace(0, 0); } - frame->push(types.i4, c->binaryOp(lir::Remainder, types.i4, a, b)); + frame->push(ir::Type::i4(), + c->binaryOp(lir::Remainder, ir::Type::i4(), a, b)); } break; case ireturn: { handleExit(t, frame); - c->return_(frame->pop(types.i4)); + c->return_(frame->pop(ir::Type::i4())); } goto next; case freturn: { handleExit(t, frame); - c->return_(frame->pop(types.f4)); + c->return_(frame->pop(ir::Type::f4())); } goto next; case istore: - frame->store(types.i4, codeBody(t, code, ip++)); + frame->store(ir::Type::i4(), codeBody(t, code, ip++)); break; case fstore: - frame->store(types.f4, codeBody(t, code, ip++)); + frame->store(ir::Type::f4(), codeBody(t, code, ip++)); break; case istore_0: - frame->store(types.i4, 0); + frame->store(ir::Type::i4(), 0); break; case fstore_0: - frame->store(types.f4, 0); + frame->store(ir::Type::f4(), 0); break; case istore_1: - frame->store(types.i4, 1); + frame->store(ir::Type::i4(), 1); break; case fstore_1: - frame->store(types.f4, 1); + frame->store(ir::Type::f4(), 1); break; case istore_2: - frame->store(types.i4, 2); + frame->store(ir::Type::i4(), 2); break; case fstore_2: - frame->store(types.f4, 2); + frame->store(ir::Type::f4(), 2); break; case istore_3: - frame->store(types.i4, 3); + frame->store(ir::Type::i4(), 3); break; case fstore_3: - frame->store(types.f4, 3); + frame->store(ir::Type::f4(), 3); break; case jsr: @@ -5167,15 +5201,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case l2d: { - frame->pushLarge(types.f8, c->i2f(types.f8, frame->popLarge(types.i8))); + frame->pushLarge(ir::Type::f8(), + c->i2f(ir::Type::f8(), frame->popLarge(ir::Type::i8()))); } break; case l2f: { - frame->push(types.f4, c->i2f(types.f4, frame->popLarge(types.i8))); + frame->push(ir::Type::f4(), + c->i2f(ir::Type::f4(), frame->popLarge(ir::Type::i8()))); } break; case l2i: - frame->push(types.i4, c->truncate(types.i4, frame->popLarge(types.i8))); + frame->push(ir::Type::i4(), + c->truncate(ir::Type::i4(), frame->popLarge(ir::Type::i8()))); break; case ladd: @@ -5184,40 +5221,41 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lsub: case lxor: case lmul: { - ir::Value* a = frame->popLarge(types.i8); - ir::Value* b = frame->popLarge(types.i8); + ir::Value* a = frame->popLarge(ir::Type::i8()); + ir::Value* b = frame->popLarge(ir::Type::i8()); frame->pushLarge( - types.i8, - c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b)); + ir::Type::i8(), + c->binaryOp( + toCompilerBinaryOp(t, instruction), ir::Type::i8(), a, b)); } break; case lcmp: { - ir::Value* a = frame->popLarge(types.i8); - ir::Value* b = frame->popLarge(types.i8); + ir::Value* a = frame->popLarge(ir::Type::i8()); + ir::Value* b = frame->popLarge(ir::Type::i8()); if (integerBranch(t, frame, code, ip, a, b, &newIp)) { goto branch; } else { - frame->push( - types.i4, - c->call(c->constant(getThunk(t, compareLongsThunk), types.address), - 0, - 0, - types.i4, - 4, - static_cast(0), - a, - static_cast(0), - b)); + frame->push(ir::Type::i4(), + c->call(c->constant(getThunk(t, compareLongsThunk), + ir::Type::iptr()), + 0, + 0, + ir::Type::i4(), + 4, + static_cast(0), + a, + static_cast(0), + b)); } } break; case lconst_0: - frame->pushLarge(types.i8, c->constant(0, types.i8)); + frame->pushLarge(ir::Type::i8(), c->constant(0, ir::Type::i8())); break; case lconst_1: - frame->pushLarge(types.i8, c->constant(1, types.i8)); + frame->pushLarge(ir::Type::i8(), c->constant(1, ir::Type::i8())); break; case ldc: @@ -5245,13 +5283,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (UNLIKELY(v == 0)) { frame->push( - types.object, + ir::Type::object(), c->call( c->constant(getThunk(t, getJClassFromReferenceThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), - types.object, + ir::Type::object(), 2, c->threadRegister(), frame->append(makePair(t, context->method, reference)))); @@ -5260,23 +5298,23 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (v) { if (objectClass(t, v) == type(t, Machine::ClassType)) { - frame->push(types.object, + frame->push(ir::Type::object(), c->call(c->constant(getThunk(t, getJClass64Thunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), - types.object, + ir::Type::object(), 2, c->threadRegister(), frame->append(v))); } else { - frame->push(types.object, frame->append(v)); + frame->push(ir::Type::object(), frame->append(v)); } } } else { ir::Type type = singletonBit(t, pool, poolSize(t, pool), index - 1) - ? types.f4 - : types.i4; + ? ir::Type::f4() + : ir::Type::i4(); frame->push(type, c->constant(singletonValue(t, pool, index - 1), type)); } @@ -5290,61 +5328,63 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint64_t v; memcpy(&v, &singletonValue(t, pool, index - 1), 8); ir::Type type = singletonBit(t, pool, poolSize(t, pool), index - 1) - ? types.f8 - : types.i8; + ? ir::Type::f8() + : ir::Type::i8(); frame->pushLarge(type, c->constant(v, type)); } break; case ldiv_: { - ir::Value* a = frame->popLarge(types.i8); - ir::Value* b = frame->popLarge(types.i8); + ir::Value* a = frame->popLarge(ir::Type::i8()); + ir::Value* b = frame->popLarge(ir::Type::i8()); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); frame->trace(0, 0); } - frame->pushLarge(types.i8, c->binaryOp(lir::Divide, types.i8, a, b)); + frame->pushLarge(ir::Type::i8(), + c->binaryOp(lir::Divide, ir::Type::i8(), a, b)); } break; case lload: - frame->loadLarge(types.i8, codeBody(t, code, ip++)); + frame->loadLarge(ir::Type::i8(), codeBody(t, code, ip++)); break; case dload: - frame->loadLarge(types.f8, codeBody(t, code, ip++)); + frame->loadLarge(ir::Type::f8(), codeBody(t, code, ip++)); break; case lload_0: - frame->loadLarge(types.i8, 0); + frame->loadLarge(ir::Type::i8(), 0); break; case dload_0: - frame->loadLarge(types.f8, 0); + frame->loadLarge(ir::Type::f8(), 0); break; case lload_1: - frame->loadLarge(types.i8, 1); + frame->loadLarge(ir::Type::i8(), 1); break; case dload_1: - frame->loadLarge(types.f8, 1); + frame->loadLarge(ir::Type::f8(), 1); break; case lload_2: - frame->loadLarge(types.i8, 2); + frame->loadLarge(ir::Type::i8(), 2); break; case dload_2: - frame->loadLarge(types.f8, 2); + frame->loadLarge(ir::Type::f8(), 2); break; case lload_3: - frame->loadLarge(types.i8, 3); + frame->loadLarge(ir::Type::i8(), 3); break; case dload_3: - frame->loadLarge(types.f8, 3); + frame->loadLarge(ir::Type::f8(), 3); break; case lneg: - frame->pushLarge(types.i8, - c->unaryOp(lir::Negate, frame->popLarge(types.i8))); + frame->pushLarge( + ir::Type::i8(), + c->unaryOp(lir::Negate, frame->popLarge(ir::Type::i8()))); break; case lookupswitch: { @@ -5352,7 +5392,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ip = (ip + 3) & ~3; // pad to four byte boundary - ir::Value* key = frame->pop(types.i4); + ir::Value* key = frame->pop(ir::Type::i4()); uint32_t defaultIp = base + codeReadInt32(t, code, ip); assert(t, defaultIp < codeLength(t, code)); @@ -5383,21 +5423,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, assert(t, start); ir::Value* address = c->call( - c->constant(getThunk(t, lookUpAddressThunk), types.address), + c->constant(getThunk(t, lookUpAddressThunk), ir::Type::iptr()), 0, 0, - types.address, + ir::Type::iptr(), 4, key, frame->absoluteAddressOperand(start), - c->constant(pairCount, types.i4), + c->constant(pairCount, ir::Type::i4()), default_); c->jmp(context->bootContext ? c->binaryOp(lir::Add, - types.address, + ir::Type::iptr(), c->memory(c->threadRegister(), - types.address, + ir::Type::iptr(), TARGET_THREAD_CODEIMAGE), address) : address); @@ -5414,95 +5454,97 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } break; case lrem: { - ir::Value* a = frame->popLarge(types.i8); - ir::Value* b = frame->popLarge(types.i8); + ir::Value* a = frame->popLarge(ir::Type::i8()); + ir::Value* b = frame->popLarge(ir::Type::i8()); if (inTryBlock(t, code, ip - 1)) { c->saveLocals(); frame->trace(0, 0); } - frame->pushLarge(types.i8, c->binaryOp(lir::Remainder, types.i8, a, b)); + frame->pushLarge(ir::Type::i8(), + c->binaryOp(lir::Remainder, ir::Type::i8(), a, b)); } break; case lreturn: { handleExit(t, frame); - c->return_(frame->popLarge(types.i8)); + c->return_(frame->popLarge(ir::Type::i8())); } goto next; case dreturn: { handleExit(t, frame); - c->return_(frame->popLarge(types.f8)); + c->return_(frame->popLarge(ir::Type::f8())); } goto next; case lshl: case lshr: case lushr: { - ir::Value* a = frame->pop(types.i4); - ir::Value* b = frame->popLarge(types.i8); + ir::Value* a = frame->pop(ir::Type::i4()); + ir::Value* b = frame->popLarge(ir::Type::i8()); frame->pushLarge( - types.i8, - c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b)); + ir::Type::i8(), + c->binaryOp( + toCompilerBinaryOp(t, instruction), ir::Type::i8(), a, b)); } break; case lstore: - frame->storeLarge(types.i8, codeBody(t, code, ip++)); + frame->storeLarge(ir::Type::i8(), codeBody(t, code, ip++)); break; case dstore: - frame->storeLarge(types.f8, codeBody(t, code, ip++)); + frame->storeLarge(ir::Type::f8(), codeBody(t, code, ip++)); break; case lstore_0: - frame->storeLarge(types.i8, 0); + frame->storeLarge(ir::Type::i8(), 0); break; case dstore_0: - frame->storeLarge(types.f8, 0); + frame->storeLarge(ir::Type::f8(), 0); break; case lstore_1: - frame->storeLarge(types.i8, 1); + frame->storeLarge(ir::Type::i8(), 1); break; case dstore_1: - frame->storeLarge(types.f8, 1); + frame->storeLarge(ir::Type::f8(), 1); break; case lstore_2: - frame->storeLarge(types.i8, 2); + frame->storeLarge(ir::Type::i8(), 2); break; case dstore_2: - frame->storeLarge(types.f8, 2); + frame->storeLarge(ir::Type::f8(), 2); break; case lstore_3: - frame->storeLarge(types.i8, 3); + frame->storeLarge(ir::Type::i8(), 3); break; case dstore_3: - frame->storeLarge(types.f8, 3); + frame->storeLarge(ir::Type::f8(), 3); break; case monitorenter: { - ir::Value* target = frame->pop(types.object); - c->call( - c->constant(getThunk(t, acquireMonitorForObjectThunk), types.address), - 0, - frame->trace(0, 0), - types.void_, - 2, - c->threadRegister(), - target); + ir::Value* target = frame->pop(ir::Type::object()); + c->call(c->constant(getThunk(t, acquireMonitorForObjectThunk), + ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::void_(), + 2, + c->threadRegister(), + target); } break; case monitorexit: { - ir::Value* target = frame->pop(types.object); - c->call( - c->constant(getThunk(t, releaseMonitorForObjectThunk), types.address), - 0, - frame->trace(0, 0), - types.void_, - 2, - c->threadRegister(), - target); + ir::Value* target = frame->pop(ir::Type::object()); + c->call(c->constant(getThunk(t, releaseMonitorForObjectThunk), + ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::void_(), + 2, + c->threadRegister(), + target); } break; case multianewarray: { @@ -5532,18 +5574,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, + t->arch->frameReturnAddressSize(); ir::Value* result - = c->call(c->constant(getThunk(t, thunk), types.address), + = c->call(c->constant(getThunk(t, thunk), ir::Type::iptr()), 0, frame->trace(0, 0), - types.object, + ir::Type::object(), 4, c->threadRegister(), frame->append(argument), - c->constant(dimensions, types.i4), - c->constant(offset, types.i4)); + c->constant(dimensions, ir::Type::i4()), + c->constant(offset, ir::Type::i4())); - frame->pop(dimensions); - frame->push(types.object, result); + frame->popFootprint(dimensions); + frame->push(ir::Type::object(), result); } break; case new_: { @@ -5570,11 +5612,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, thunk = makeNewFromReferenceThunk; } - frame->push(types.object, - c->call(c->constant(getThunk(t, thunk), types.address), + frame->push(ir::Type::object(), + c->call(c->constant(getThunk(t, thunk), ir::Type::iptr()), 0, frame->trace(0, 0), - types.object, + ir::Type::object(), 2, c->threadRegister(), frame->append(argument))); @@ -5583,28 +5625,28 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case newarray: { uint8_t type = codeBody(t, code, ip++); - ir::Value* length = frame->pop(types.i4); + ir::Value* length = frame->pop(ir::Type::i4()); - frame->push( - types.object, - c->call(c->constant(getThunk(t, makeBlankArrayThunk), types.address), - 0, - frame->trace(0, 0), - types.object, - 3, - c->threadRegister(), - c->constant(type, types.i4), - length)); + frame->push(ir::Type::object(), + c->call(c->constant(getThunk(t, makeBlankArrayThunk), + ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::object(), + 3, + c->threadRegister(), + c->constant(type, ir::Type::i4()), + length)); } break; case nop: break; case pop_: - frame->pop(1); + frame->popFootprint(1); break; case pop2: - frame->pop(2); + frame->popFootprint(2); break; case putfield: @@ -5629,13 +5671,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (classNeedsInit(t, fieldClass(t, field))) { PROTECT(t, field); - c->call(c->constant(getThunk(t, tryInitClassThunk), types.address), - 0, - frame->trace(0, 0), - types.void_, - 2, - c->threadRegister(), - frame->append(fieldClass(t, field))); + c->call( + c->constant(getThunk(t, tryInitClassThunk), ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::void_(), + 2, + c->threadRegister(), + frame->append(fieldClass(t, field))); } staticTable = classStaticTable(t, fieldClass(t, field)); @@ -5655,10 +5698,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, PROTECT(t, field); c->call(c->constant(getThunk(t, acquireMonitorForObjectThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), - types.void_, + ir::Type::void_(), 2, c->threadRegister(), frame->append(field)); @@ -5676,7 +5719,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, table = frame->append(staticTable); } else { - table = frame->pop(types.object); + table = frame->pop(ir::Type::object()); } switch (fieldCode) { @@ -5684,61 +5727,69 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case BooleanField: c->store( value, - c->memory(table, types.i1, targetFieldOffset(context, field))); + c->memory( + table, ir::Type::i1(), targetFieldOffset(context, field))); break; case CharField: case ShortField: c->store( value, - c->memory(table, types.i2, targetFieldOffset(context, field))); + c->memory( + table, ir::Type::i2(), targetFieldOffset(context, field))); break; case FloatField: c->store( value, - c->memory(table, types.f4, targetFieldOffset(context, field))); + c->memory( + table, ir::Type::f4(), targetFieldOffset(context, field))); break; case IntField: c->store( value, - c->memory(table, types.i4, targetFieldOffset(context, field))); + c->memory( + table, ir::Type::i4(), targetFieldOffset(context, field))); break; case DoubleField: c->store( value, - c->memory(table, types.f8, targetFieldOffset(context, field))); + c->memory( + table, ir::Type::f8(), targetFieldOffset(context, field))); break; case LongField: c->store( value, - c->memory(table, types.i8, targetFieldOffset(context, field))); + c->memory( + table, ir::Type::i8(), targetFieldOffset(context, field))); break; case ObjectField: if (instruction == putfield) { - c->call(c->constant(getThunk(t, setMaybeNullThunk), types.address), - 0, - frame->trace(0, 0), - types.void_, - 4, - c->threadRegister(), - table, - c->constant(targetFieldOffset(context, field), types.i4), - value); + c->call( + c->constant(getThunk(t, setMaybeNullThunk), ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::void_(), + 4, + c->threadRegister(), + table, + c->constant(targetFieldOffset(context, field), ir::Type::i4()), + value); } else { - c->call(c->constant(getThunk(t, setThunk), types.address), - 0, - 0, - types.void_, - 4, - c->threadRegister(), - table, - c->constant(targetFieldOffset(context, field), types.i4), - value); + c->call( + c->constant(getThunk(t, setThunk), ir::Type::iptr()), + 0, + 0, + ir::Type::void_(), + 4, + c->threadRegister(), + table, + c->constant(targetFieldOffset(context, field), ir::Type::i4()), + value); } break; @@ -5750,10 +5801,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, and (fieldCode == DoubleField or fieldCode == LongField)) { c->call(c->constant(getThunk(t, releaseMonitorForObjectThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), - types.void_, + ir::Type::void_(), 2, c->threadRegister(), frame->append(field)); @@ -5780,7 +5831,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (instruction == putstatic) { c->call( c->constant(getThunk(t, setStaticFieldValueFromReferenceThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), rType, @@ -5789,10 +5840,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->append(pair), value); } else { - ir::Value* instance = frame->pop(types.object); + ir::Value* instance = frame->pop(ir::Type::object()); c->call(c->constant(getThunk(t, setFieldValueFromReferenceThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), rType, @@ -5809,7 +5860,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (instruction == putstatic) { c->call(c->constant( getThunk(t, setStaticLongFieldValueFromReferenceThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), rType, @@ -5819,11 +5870,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, static_cast(0), value); } else { - ir::Value* instance = frame->pop(types.object); + ir::Value* instance = frame->pop(ir::Type::object()); c->call( c->constant(getThunk(t, setLongFieldValueFromReferenceThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), rType, @@ -5841,7 +5892,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->call( c->constant( getThunk(t, setStaticObjectFieldValueFromReferenceThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), rType, @@ -5850,11 +5901,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->append(pair), value); } else { - ir::Value* instance = frame->pop(types.object); + ir::Value* instance = frame->pop(ir::Type::object()); c->call( c->constant(getThunk(t, setObjectFieldValueFromReferenceThunk), - types.address), + ir::Type::iptr()), 0, frame->trace(0, 0), rType, @@ -5889,9 +5940,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, goto next; case sipush: - frame->push(types.i4, + frame->push(ir::Type::i4(), c->constant(static_cast(codeReadInt16(t, code, ip)), - types.i4)); + ir::Type::i4())); break; case swap: @@ -5928,14 +5979,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } assert(t, start); - ir::Value* key = frame->pop(types.i4); + ir::Value* key = frame->pop(ir::Type::i4()); c->condJump(lir::JumpIfLess, - c->constant(bottom, types.i4), + c->constant(bottom, ir::Type::i4()), key, frame->machineIpValue(defaultIp)); - c->save(types.i4, key); + c->save(ir::Type::i4(), key); new (stack.push(sizeof(SwitchState))) SwitchState (c->saveState(), count, defaultIp, key, start, bottom, top); @@ -5947,11 +5998,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case wide: { switch (codeBody(t, code, ip++)) { case aload: { - frame->load(types.object, codeReadInt16(t, code, ip)); + frame->load(ir::Type::object(), codeReadInt16(t, code, ip)); } break; case astore: { - frame->store(types.object, codeReadInt16(t, code, ip)); + frame->store(ir::Type::object(), codeReadInt16(t, code, ip)); } break; case iinc: { @@ -5960,28 +6011,28 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, storeLocal(context, 1, - types.i4, + ir::Type::i4(), c->binaryOp(lir::Add, - types.i4, - c->constant(count, types.i4), - loadLocal(context, 1, types.i4, index)), + ir::Type::i4(), + c->constant(count, ir::Type::i4()), + loadLocal(context, 1, ir::Type::i4(), index)), index); } break; case iload: { - frame->load(types.i4, codeReadInt16(t, code, ip)); + frame->load(ir::Type::i4(), codeReadInt16(t, code, ip)); } break; case istore: { - frame->store(types.i4, codeReadInt16(t, code, ip)); + frame->store(ir::Type::i4(), codeReadInt16(t, code, ip)); } break; case lload: { - frame->loadLarge(types.i8, codeReadInt16(t, code, ip)); + frame->loadLarge(ir::Type::i8(), codeReadInt16(t, code, ip)); } break; case lstore: { - frame->storeLarge(types.i8, codeReadInt16(t, code, ip)); + frame->storeLarge(ir::Type::i8(), codeReadInt16(t, code, ip)); } break; case ret: { @@ -6030,11 +6081,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->restoreState(s->state); c->condJump(lir::JumpIfGreater, - c->constant(s->top, types.i4), + c->constant(s->top, ir::Type::i4()), s->key, frame->machineIpValue(s->defaultIp)); - c->save(types.i4, s->key); + c->save(ir::Type::i4(), s->key); ip = s->defaultIp; stack.pushValue(Untable1); } goto start; @@ -6051,27 +6102,28 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->restoreState(s->state); ir::Value* normalizedKey - = (s->bottom ? c->binaryOp(lir::Subtract, - types.i4, - c->constant(s->bottom, types.i4), - s->key) - : s->key); + = (s->bottom + ? c->binaryOp(lir::Subtract, + ir::Type::i4(), + c->constant(s->bottom, ir::Type::i4()), + s->key) + : s->key); ir::Value* entry = c->memory(frame->absoluteAddressOperand(s->start), - types.address, + ir::Type::iptr(), 0, normalizedKey); c->jmp(c->load(ir::SignExtend, context->bootContext ? c->binaryOp(lir::Add, - types.address, + ir::Type::iptr(), c->memory(c->threadRegister(), - types.address, + ir::Type::iptr(), TARGET_THREAD_CODEIMAGE), entry) : entry, - types.address)); + ir::Type::iptr())); s->state = c->saveState(); } goto switchloop; @@ -6906,8 +6958,8 @@ compile(MyThread* t, Context* context) unsigned index = methodParameterFootprint(t, context->method); if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { - frame.set(--index, frame.types.object); - c->initLocal(index, frame.types.object); + frame.set(--index, ir::Type::object()); + c->initLocal(index, ir::Type::object()); } for (MethodSpecIterator it @@ -6918,30 +6970,30 @@ compile(MyThread* t, Context* context) switch (*it.next()) { case 'L': case '[': - frame.set(--index, frame.types.object); - c->initLocal(index, frame.types.object); + frame.set(--index, ir::Type::object()); + c->initLocal(index, ir::Type::object()); break; case 'J': - frame.set(--index, frame.types.i8); - frame.set(--index, frame.types.i8); - c->initLocal(index, frame.types.i8); + frame.set(--index, ir::Type::i8()); + frame.set(--index, ir::Type::i8()); + c->initLocal(index, ir::Type::i8()); break; case 'D': - frame.set(--index, frame.types.f8); - frame.set(--index, frame.types.f8); - c->initLocal(index, frame.types.f8); + frame.set(--index, ir::Type::f8()); + frame.set(--index, ir::Type::f8()); + c->initLocal(index, ir::Type::f8()); break; case 'F': - frame.set(--index, frame.types.i4); - c->initLocal(index, frame.types.f4); + frame.set(--index, ir::Type::i4()); + c->initLocal(index, ir::Type::f4()); break; default: - frame.set(--index, frame.types.i4); - c->initLocal(index, frame.types.i4); + frame.set(--index, ir::Type::i4()); + c->initLocal(index, ir::Type::i4()); break; } } @@ -7004,7 +7056,7 @@ compile(MyThread* t, Context* context) for (unsigned i = 1; i < codeMaxStack(t, methodCode(t, context->method)); ++i) { - frame2.set(localSize(t, context->method) + i, frame2.types.i4); + frame2.set(localSize(t, context->method) + i, ir::Type::i4()); } compile(t, &frame2, exceptionHandlerIp(eh), start); From 05d80aee8ba5e8e8de315b8929fc9773986b9a7f Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sun, 1 Jun 2014 14:41:12 -0600 Subject: [PATCH 89/89] remove static references to TargetBytesPerWord in Compiler --- include/avian/codegen/architecture.h | 4 + include/avian/codegen/ir.h | 2 +- src/codegen/compiler.cpp | 28 +-- src/codegen/compiler/context.cpp | 67 +++--- src/codegen/compiler/context.h | 1 + src/codegen/compiler/event.cpp | 342 +++++++++++++++------------ src/codegen/compiler/frame.cpp | 12 +- src/codegen/compiler/promise.cpp | 7 +- src/codegen/compiler/site.cpp | 51 ++-- src/codegen/compiler/value.cpp | 3 +- src/codegen/target/arm/assembler.cpp | 5 + src/codegen/target/x86/assembler.cpp | 5 + src/debug-util.cpp | 8 - 13 files changed, 299 insertions(+), 236 deletions(-) diff --git a/include/avian/codegen/architecture.h b/include/avian/codegen/architecture.h index e3b2c3d27e..0c82fbc207 100644 --- a/include/avian/codegen/architecture.h +++ b/include/avian/codegen/architecture.h @@ -11,6 +11,8 @@ #ifndef AVIAN_CODEGEN_ARCHITECTURE_H #define AVIAN_CODEGEN_ARCHITECTURE_H +#include "ir.h" + namespace vm { class Zone; } @@ -57,6 +59,8 @@ virtual int returnHigh() = 0; virtual int virtualCallTarget() = 0; virtual int virtualCallIndex() = 0; +virtual ir::TargetInfo targetInfo() = 0; + virtual bool bigEndian() = 0; virtual uintptr_t maximumImmediateJump() = 0; diff --git a/include/avian/codegen/ir.h b/include/avian/codegen/ir.h index ae95a2efa5..8b2b48aa9d 100644 --- a/include/avian/codegen/ir.h +++ b/include/avian/codegen/ir.h @@ -19,7 +19,7 @@ class TargetInfo { public: unsigned pointerSize; - TargetInfo(unsigned pointerSize) : pointerSize(pointerSize) + explicit TargetInfo(unsigned pointerSize) : pointerSize(pointerSize) { } }; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index dc9bbdbe4b..16972c61c7 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2281,7 +2281,7 @@ class MyCompiler: public Compiler { static_cast(base), displacement, static_cast(index), - index == 0 ? 1 : type.size(TargetBytesPerWord), + index == 0 ? 1 : type.size(c.targetInfo), result); return result; @@ -2585,10 +2585,10 @@ class MyCompiler: public Compiler { Value* dst = value(&c, type); appendMove(&c, lir::Move, - src->type.size(TargetBytesPerWord), - src->type.size(TargetBytesPerWord), + src->type.size(c.targetInfo), + src->type.size(c.targetInfo), static_cast(src), - type.size(TargetBytesPerWord), + type.size(c.targetInfo), dst); return dst; } @@ -2602,11 +2602,11 @@ class MyCompiler: public Compiler { appendMove(&c, signExtend == ir::SignExtend ? lir::Move : lir::MoveZ, TargetBytesPerWord, - truncateType.size(TargetBytesPerWord), + truncateType.size(c.targetInfo), static_cast(src), - extendType.size(TargetBytesPerWord) < TargetBytesPerWord + extendType.size(c.targetInfo) < TargetBytesPerWord ? TargetBytesPerWord - : extendType.size(TargetBytesPerWord), + : extendType.size(c.targetInfo), dst); return dst; } @@ -2617,10 +2617,10 @@ class MyCompiler: public Compiler { appendMove(&c, lir::Move, - src->type.size(TargetBytesPerWord), - src->type.size(TargetBytesPerWord), + src->type.size(c.targetInfo), + src->type.size(c.targetInfo), static_cast(src), - dst->type.size(TargetBytesPerWord), + dst->type.size(c.targetInfo), static_cast(dst)); } @@ -2633,12 +2633,12 @@ class MyCompiler: public Compiler { Value* dst = value(&c, dstType); appendMove(&c, signExtend == ir::SignExtend ? lir::Move : lir::MoveZ, - src->type.size(TargetBytesPerWord), - src->type.size(TargetBytesPerWord), + src->type.size(c.targetInfo), + src->type.size(c.targetInfo), static_cast(src), - dstType.size(TargetBytesPerWord) < TargetBytesPerWord + dstType.size(c.targetInfo) < TargetBytesPerWord ? TargetBytesPerWord - : dstType.size(TargetBytesPerWord), + : dstType.size(c.targetInfo), dst); return dst; } diff --git a/src/codegen/compiler/context.cpp b/src/codegen/compiler/context.cpp index 24436f1ed3..404b9aba28 100644 --- a/src/codegen/compiler/context.cpp +++ b/src/codegen/compiler/context.cpp @@ -17,38 +17,41 @@ namespace avian { namespace codegen { namespace compiler { -Context::Context(vm::System* system, Assembler* assembler, vm::Zone* zone, - Compiler::Client* client): - system(system), - assembler(assembler), - arch(assembler->arch()), - zone(zone), - client(client), - stack(0), - locals(0), - saved(0), - predecessor(0), - regFile(arch->registerFile()), - regAlloc(system, arch->registerFile()), - registerResources - (static_cast - (zone->allocate(sizeof(RegisterResource) * regFile->allRegisters.limit))), - frameResources(0), - acquiredResources(0), - firstConstant(0), - lastConstant(0), - machineCode(0), - firstEvent(0), - lastEvent(0), - forkState(0), - firstBlock(0), - logicalIp(-1), - constantCount(0), - parameterFootprint(0), - localFootprint(0), - machineCodeSize(0), - alignedFrameSize(0), - availableGeneralRegisterCount(regFile->generalRegisters.limit - regFile->generalRegisters.start) +Context::Context(vm::System* system, + Assembler* assembler, + vm::Zone* zone, + Compiler::Client* client) + : system(system), + assembler(assembler), + arch(assembler->arch()), + zone(zone), + client(client), + stack(0), + locals(0), + saved(0), + predecessor(0), + regFile(arch->registerFile()), + regAlloc(system, arch->registerFile()), + registerResources(static_cast(zone->allocate( + sizeof(RegisterResource) * regFile->allRegisters.limit))), + frameResources(0), + acquiredResources(0), + firstConstant(0), + lastConstant(0), + machineCode(0), + firstEvent(0), + lastEvent(0), + forkState(0), + firstBlock(0), + logicalIp(-1), + constantCount(0), + parameterFootprint(0), + localFootprint(0), + machineCodeSize(0), + alignedFrameSize(0), + availableGeneralRegisterCount(regFile->generalRegisters.limit + - regFile->generalRegisters.start), + targetInfo(arch->targetInfo()) { for (unsigned i = regFile->generalRegisters.start; i < regFile->generalRegisters.limit; ++i) { new (registerResources + i) RegisterResource(arch->reserved(i)); diff --git a/src/codegen/compiler/context.h b/src/codegen/compiler/context.h index 9d03a96f35..03708f39c1 100644 --- a/src/codegen/compiler/context.h +++ b/src/codegen/compiler/context.h @@ -125,6 +125,7 @@ class Context { unsigned machineCodeSize; unsigned alignedFrameSize; unsigned availableGeneralRegisterCount; + ir::TargetInfo targetInfo; }; inline Aborter* getAborter(Context* c) { diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index d4045b9aab..44685f3cc0 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -130,7 +130,7 @@ void Event::addReads(Context* c, Value* v, unsigned size, { SingleRead* r = read(c, lowMask, lowSuccessor); this->addRead(c, v, r); - if (size > vm::TargetBytesPerWord) { + if (size > c->targetInfo.pointerSize) { r->high_ = v->nextWord; this->addRead(c, v->nextWord, highMask, highSuccessor); } @@ -269,7 +269,7 @@ void slicePush(Context* c, if (footprint > 1) { assert(c, footprint == 2); - if (vm::TargetBytesPerWord == 4) { + if (c->targetInfo.pointerSize == 4) { low->maybeSplit(c); high = slicePushWord(c, low->nextWord, stackBase, slice); } else { @@ -376,9 +376,10 @@ class CallEvent: public Event { { bool thunk; OperandMask op; - c->arch->plan - ((flags & Compiler::Aligned) ? lir::AlignedCall : lir::Call, vm::TargetBytesPerWord, - op, &thunk); + c->arch->plan((flags & Compiler::Aligned) ? lir::AlignedCall : lir::Call, + c->targetInfo.pointerSize, + op, + &thunk); assert(c, not thunk); @@ -395,12 +396,12 @@ class CallEvent: public Event { for (int i = stackArgumentFootprint - 1; i >= 0; --i) { Value* v = static_cast(arguments[i]); - if ((vm::TargetBytesPerWord == 8 + if ((c->targetInfo.pointerSize == 8 && (v == 0 || (i >= 1 && arguments[i - 1] == 0))) - || (vm::TargetBytesPerWord == 4 && v->nextWord != v)) { - assert( - c, - vm::TargetBytesPerWord == 8 or v->nextWord == arguments[i - 1]); + || (c->targetInfo.pointerSize == 4 && v->nextWord != v)) { + assert(c, + c->targetInfo.pointerSize == 8 + or v->nextWord == arguments[i - 1]); arguments[i] = arguments[i - 1]; --i; @@ -553,7 +554,7 @@ class CallEvent: public Event { op = lir::Call; } - apply(c, op, vm::TargetBytesPerWord, address->source, address->source); + apply(c, op, c->targetInfo.pointerSize, address->source, address->source); if (traceHandler) { traceHandler->handleTrace(codePromise(c, c->assembler->offset(true)), @@ -576,11 +577,10 @@ class CallEvent: public Event { clean(c, this, stackBefore, localsBefore, reads, popIndex); - if (resultValue->type.size(vm::TargetBytesPerWord) - and live(c, resultValue)) { + if (resultValue->type.size(c->targetInfo) and live(c, resultValue)) { resultValue->addSite(c, registerSite(c, c->arch->returnLow())); - if (resultValue->type.size(vm::TargetBytesPerWord) - > vm::TargetBytesPerWord and live(c, resultValue->nextWord)) { + if (resultValue->type.size(c->targetInfo) > c->targetInfo.pointerSize + and live(c, resultValue->nextWord)) { resultValue->nextWord->addSite(c, registerSite(c, c->arch->returnHigh())); } @@ -628,7 +628,7 @@ class ReturnEvent: public Event { if (value) { this->addReads(c, value, - value->type.size(vm::TargetBytesPerWord), + value->type.size(c->targetInfo), SiteMask::fixedRegisterMask(c->arch->returnLow()), SiteMask::fixedRegisterMask(c->arch->returnHigh())); } @@ -680,18 +680,23 @@ class MoveEvent: public Event { assert(c, srcSelectSize <= srcSize); bool noop = srcSelectSize >= dstSize; - - if (dstSize > vm::TargetBytesPerWord) { + + if (dstSize > c->targetInfo.pointerSize) { dstValue->grow(c); } - if (srcSelectSize > vm::TargetBytesPerWord) { + if (srcSelectSize > c->targetInfo.pointerSize) { srcValue->maybeSplit(c); } - this->addReads(c, srcValue, srcSelectSize, srcLowMask, noop ? dstValue : 0, - srcHighMask, - noop and dstSize > vm::TargetBytesPerWord ? dstValue->nextWord : 0); + this->addReads( + c, + srcValue, + srcSelectSize, + srcLowMask, + noop ? dstValue : 0, + srcHighMask, + noop and dstSize > c->targetInfo.pointerSize ? dstValue->nextWord : 0); } virtual const char* name() { @@ -714,47 +719,61 @@ class MoveEvent: public Event { SiteMask dstLowMask = SiteMask::lowPart(dst); SiteMask dstHighMask = SiteMask::highPart(dst); - if (srcSelectSize >= vm::TargetBytesPerWord - and dstSize >= vm::TargetBytesPerWord - and srcSelectSize >= dstSize) - { + if (srcSelectSize >= c->targetInfo.pointerSize + and dstSize >= c->targetInfo.pointerSize and srcSelectSize >= dstSize) { if (dstValue->target) { - if (dstSize > vm::TargetBytesPerWord) { - if (srcValue->source->registerSize(c) > vm::TargetBytesPerWord) { + if (dstSize > c->targetInfo.pointerSize) { + if (srcValue->source->registerSize(c) > c->targetInfo.pointerSize) { apply(c, lir::Move, srcSelectSize, srcValue->source, srcValue->source, dstSize, dstValue->target, dstValue->target); if (live(c, dstValue) == 0) { dstValue->removeSite(c, dstValue->target); - if (dstSize > vm::TargetBytesPerWord) { + if (dstSize > c->targetInfo.pointerSize) { dstValue->nextWord->removeSite(c, dstValue->nextWord->target); } } } else { srcValue->nextWord->source->freeze(c, srcValue->nextWord); - maybeMove(c, lir::Move, vm::TargetBytesPerWord, vm::TargetBytesPerWord, srcValue, - vm::TargetBytesPerWord, dstValue, dstLowMask); + maybeMove(c, + lir::Move, + c->targetInfo.pointerSize, + c->targetInfo.pointerSize, + srcValue, + c->targetInfo.pointerSize, + dstValue, + dstLowMask); srcValue->nextWord->source->thaw(c, srcValue->nextWord); - maybeMove - (c, lir::Move, vm::TargetBytesPerWord, vm::TargetBytesPerWord, srcValue->nextWord, - vm::TargetBytesPerWord, dstValue->nextWord, dstHighMask); + maybeMove(c, + lir::Move, + c->targetInfo.pointerSize, + c->targetInfo.pointerSize, + srcValue->nextWord, + c->targetInfo.pointerSize, + dstValue->nextWord, + dstHighMask); } } else { - maybeMove(c, lir::Move, vm::TargetBytesPerWord, vm::TargetBytesPerWord, srcValue, - vm::TargetBytesPerWord, dstValue, dstLowMask); + maybeMove(c, + lir::Move, + c->targetInfo.pointerSize, + c->targetInfo.pointerSize, + srcValue, + c->targetInfo.pointerSize, + dstValue, + dstLowMask); } } else { Site* low = pickSiteOrMove(c, srcValue, dstValue, 0, 0); - if (dstSize > vm::TargetBytesPerWord) { + if (dstSize > c->targetInfo.pointerSize) { pickSiteOrMove(c, srcValue->nextWord, dstValue->nextWord, low, 1); } } - } else if (srcSelectSize <= vm::TargetBytesPerWord - and dstSize <= vm::TargetBytesPerWord) - { + } else if (srcSelectSize <= c->targetInfo.pointerSize + and dstSize <= c->targetInfo.pointerSize) { maybeMove(c, op, srcSize, @@ -764,8 +783,8 @@ class MoveEvent: public Event { dstValue, dstLowMask); } else { - assert(c, srcSize == vm::TargetBytesPerWord); - assert(c, srcSelectSize == vm::TargetBytesPerWord); + assert(c, srcSize == c->targetInfo.pointerSize); + assert(c, srcSelectSize == c->targetInfo.pointerSize); if (dstValue->nextWord->target or live(c, dstValue->nextWord)) { assert(c, dstLowMask.typeMask & (1 << lir::RegisterOperand)); @@ -785,8 +804,14 @@ class MoveEvent: public Event { srcb, dstb, srcValue); } - apply(c, lir::Move, vm::TargetBytesPerWord, srcValue->source, srcValue->source, - vm::TargetBytesPerWord, low, low); + apply(c, + lir::Move, + c->targetInfo.pointerSize, + srcValue->source, + srcValue->source, + c->targetInfo.pointerSize, + low, + low); low->thaw(c, dstValue); @@ -809,7 +834,14 @@ class MoveEvent: public Event { srcb, dstb, dstValue, dstValue->nextWord); } - apply(c, lir::Move, vm::TargetBytesPerWord, low, low, dstSize, low, high); + apply(c, + lir::Move, + c->targetInfo.pointerSize, + low, + low, + dstSize, + low, + high); high->thaw(c, dstValue->nextWord); @@ -864,7 +896,7 @@ void freezeSource(Context* c, unsigned size, Value* v) { v->source->freeze(c, v); - if (size > vm::TargetBytesPerWord) { + if (size > c->targetInfo.pointerSize) { v->nextWord->source->freeze(c, v->nextWord); } } @@ -873,7 +905,7 @@ void thawSource(Context* c, unsigned size, Value* v) { v->source->thaw(c, v); - if (size > vm::TargetBytesPerWord) { + if (size > c->targetInfo.pointerSize) { v->nextWord->source->thaw(c, v->nextWord); } } @@ -948,12 +980,11 @@ class CombineEvent: public Event { { this->addReads(c, firstValue, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), firstLowMask, firstHighMask); - if (resultValue->type.size(vm::TargetBytesPerWord) - > vm::TargetBytesPerWord) { + if (resultValue->type.size(c->targetInfo) > c->targetInfo.pointerSize) { resultValue->grow(c); } @@ -961,7 +992,7 @@ class CombineEvent: public Event { this->addReads(c, secondValue, - secondValue->type.size(vm::TargetBytesPerWord), + secondValue->type.size(c->targetInfo), secondLowMask, condensed ? resultValue : 0, secondHighMask, @@ -984,27 +1015,27 @@ class CombineEvent: public Event { assert(c, secondValue->source->type(c) == secondValue->nextWord->source->type(c)); - freezeSource(c, firstValue->type.size(vm::TargetBytesPerWord), firstValue); + freezeSource(c, firstValue->type.size(c->targetInfo), firstValue); OperandMask cMask; c->arch->planDestination( op, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), OperandMask( 1 << firstValue->source->type(c), (static_cast( firstValue->nextWord->source->registerMask(c)) << 32) | static_cast(firstValue->source->registerMask(c))), - secondValue->type.size(vm::TargetBytesPerWord), + secondValue->type.size(c->targetInfo), OperandMask( 1 << secondValue->source->type(c), (static_cast( secondValue->nextWord->source->registerMask(c)) << 32) | static_cast(secondValue->source->registerMask(c))), - resultValue->type.size(vm::TargetBytesPerWord), + resultValue->type.size(c->targetInfo), cMask); SiteMask resultLowMask = SiteMask::lowPart(cMask); @@ -1012,7 +1043,7 @@ class CombineEvent: public Event { Site* low = getTarget(c, secondValue, resultValue, resultLowMask); unsigned lowSize = low->registerSize(c); - Site* high = (resultValue->type.size(vm::TargetBytesPerWord) > lowSize + Site* high = (resultValue->type.size(c->targetInfo) > lowSize ? getTarget(c, secondValue->nextWord, resultValue->nextWord, @@ -1026,30 +1057,30 @@ class CombineEvent: public Event { apply(c, op, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), firstValue->source, firstValue->nextWord->source, - secondValue->type.size(vm::TargetBytesPerWord), + secondValue->type.size(c->targetInfo), secondValue->source, secondValue->nextWord->source, - resultValue->type.size(vm::TargetBytesPerWord), + resultValue->type.size(c->targetInfo), low, high); - thawSource(c, firstValue->type.size(vm::TargetBytesPerWord), firstValue); + thawSource(c, firstValue->type.size(c->targetInfo), firstValue); for (Read* r = reads; r; r = r->eventNext) { popRead(c, this, r->value); } low->thaw(c, secondValue); - if (resultValue->type.size(vm::TargetBytesPerWord) > lowSize) { + if (resultValue->type.size(c->targetInfo) > lowSize) { high->thaw(c, secondValue->nextWord); } if (live(c, resultValue)) { resultValue->addSite(c, low); - if (resultValue->type.size(vm::TargetBytesPerWord) > lowSize + if (resultValue->type.size(c->targetInfo) > lowSize and live(c, resultValue->nextWord)) { resultValue->nextWord->addSite(c, high); } @@ -1072,11 +1103,11 @@ void appendCombine(Context* c, OperandMask firstMask; OperandMask secondMask; c->arch->planSource(op, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), firstMask, - secondValue->type.size(vm::TargetBytesPerWord), + secondValue->type.size(c->targetInfo), secondMask, - resultValue->type.size(vm::TargetBytesPerWord), + resultValue->type.size(c->targetInfo), &thunk); if (thunk) { @@ -1087,25 +1118,24 @@ void appendCombine(Context* c, bool threadParameter; intptr_t handler = c->client->getThunk(op, - firstValue->type.size(vm::TargetBytesPerWord), - resultValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), + resultValue->type.size(c->targetInfo), &threadParameter); - unsigned stackSize - = ceilingDivide(secondValue->type.size(vm::TargetBytesPerWord), - vm::TargetBytesPerWord) - + ceilingDivide(firstValue->type.size(vm::TargetBytesPerWord), - vm::TargetBytesPerWord); + unsigned stackSize = ceilingDivide(secondValue->type.size(c->targetInfo), + c->targetInfo.pointerSize) + + ceilingDivide(firstValue->type.size(c->targetInfo), + c->targetInfo.pointerSize); slicePush(c, - ceilingDivide(secondValue->type.size(vm::TargetBytesPerWord), - vm::TargetBytesPerWord), + ceilingDivide(secondValue->type.size(c->targetInfo), + c->targetInfo.pointerSize), secondValue, stackBase, slice); slicePush(c, - ceilingDivide(firstValue->type.size(vm::TargetBytesPerWord), - vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(c->targetInfo), + c->targetInfo.pointerSize), firstValue, stackBase, slice); @@ -1149,14 +1179,13 @@ class TranslateEvent: public Event { { bool condensed = c->arch->alwaysCondensed(op); - if (resultValue->type.size(vm::TargetBytesPerWord) - > vm::TargetBytesPerWord) { + if (resultValue->type.size(c->targetInfo) > c->targetInfo.pointerSize) { resultValue->grow(c); } this->addReads(c, firstValue, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), valueLowMask, condensed ? resultValue : 0, valueHighMask, @@ -1174,14 +1203,14 @@ class TranslateEvent: public Event { c->arch->planDestination( op, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), OperandMask( 1 << firstValue->source->type(c), (static_cast( firstValue->nextWord->source->registerMask(c)) << 32) | static_cast(firstValue->source->registerMask(c))), - resultValue->type.size(vm::TargetBytesPerWord), + resultValue->type.size(c->targetInfo), bMask); SiteMask resultLowMask = SiteMask::lowPart(bMask); @@ -1189,7 +1218,7 @@ class TranslateEvent: public Event { Site* low = getTarget(c, firstValue, resultValue, resultLowMask); unsigned lowSize = low->registerSize(c); - Site* high = (resultValue->type.size(vm::TargetBytesPerWord) > lowSize + Site* high = (resultValue->type.size(c->targetInfo) > lowSize ? getTarget(c, firstValue->nextWord, resultValue->nextWord, @@ -1198,10 +1227,10 @@ class TranslateEvent: public Event { apply(c, op, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), firstValue->source, firstValue->nextWord->source, - resultValue->type.size(vm::TargetBytesPerWord), + resultValue->type.size(c->targetInfo), low, high); @@ -1210,13 +1239,13 @@ class TranslateEvent: public Event { } low->thaw(c, firstValue); - if (resultValue->type.size(vm::TargetBytesPerWord) > lowSize) { + if (resultValue->type.size(c->targetInfo) > lowSize) { high->thaw(c, firstValue->nextWord); } if (live(c, resultValue)) { resultValue->addSite(c, low); - if (resultValue->type.size(vm::TargetBytesPerWord) > lowSize + if (resultValue->type.size(c->targetInfo) > lowSize and live(c, resultValue->nextWord)) { resultValue->nextWord->addSite(c, high); } @@ -1237,19 +1266,19 @@ void appendTranslate(Context* c, Value* resultValue) { assert(c, - firstValue->type.size(vm::TargetBytesPerWord) - == firstValue->type.size(vm::TargetBytesPerWord)); + firstValue->type.size(c->targetInfo) + == firstValue->type.size(c->targetInfo)); assert(c, - resultValue->type.size(vm::TargetBytesPerWord) - == resultValue->type.size(vm::TargetBytesPerWord)); + resultValue->type.size(c->targetInfo) + == resultValue->type.size(c->targetInfo)); bool thunk; OperandMask first; c->arch->planSource(op, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), first, - resultValue->type.size(vm::TargetBytesPerWord), + resultValue->type.size(c->targetInfo), &thunk); if (thunk) { @@ -1257,8 +1286,8 @@ void appendTranslate(Context* c, FixedSliceStack slice; slicePush(c, - ceilingDivide(firstValue->type.size(vm::TargetBytesPerWord), - vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(c->targetInfo), + c->targetInfo.pointerSize), firstValue, stackBase, slice); @@ -1266,12 +1295,11 @@ void appendTranslate(Context* c, appendCall(c, value(c, ir::Type::addr(), - constantSite( - c, - c->client->getThunk( - op, - firstValue->type.size(vm::TargetBytesPerWord), - resultValue->type.size(vm::TargetBytesPerWord)))), + constantSite(c, + c->client->getThunk( + op, + firstValue->type.size(c->targetInfo), + resultValue->type.size(c->targetInfo)))), ir::NativeCallingConvention, 0, 0, @@ -1374,7 +1402,7 @@ class MemoryEvent: public Event { popRead(c, this, base); if (index) { - if (vm::TargetBytesPerWord == 8 and indexRegister != lir::NoRegister) { + if (c->targetInfo.pointerSize == 8 and indexRegister != lir::NoRegister) { apply(c, lir::Move, 4, index->source, index->source, 8, index->source, index->source); } @@ -1544,22 +1572,22 @@ class BranchEvent: public Event { { this->addReads(c, firstValue, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), firstLowMask, firstHighMask); this->addReads(c, secondValue, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), secondLowMask, secondHighMask); OperandMask dstMask; c->arch->planDestination(op, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), OperandMask(0, 0), - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), OperandMask(0, 0), - vm::TargetBytesPerWord, + c->targetInfo.pointerSize, dstMask); this->addRead(c, addressValue, SiteMask::lowPart(dstMask)); @@ -1582,8 +1610,7 @@ class BranchEvent: public Event { int64_t firstConstVal = firstConstant->value->value(); int64_t secondConstVal = secondConstant->value->value(); - if (firstValue->type.size(vm::TargetBytesPerWord) - > vm::TargetBytesPerWord) { + if (firstValue->type.size(c->targetInfo) > c->targetInfo.pointerSize) { firstConstVal |= findConstantSite (c, firstValue->nextWord)->value->value() << 32; secondConstVal |= findConstantSite @@ -1592,35 +1619,35 @@ class BranchEvent: public Event { if (shouldJump(c, op, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), firstConstVal, secondConstVal)) { - apply(c, lir::Jump, vm::TargetBytesPerWord, addressValue->source, addressValue->source); + apply(c, + lir::Jump, + c->targetInfo.pointerSize, + addressValue->source, + addressValue->source); } } else { - freezeSource( - c, firstValue->type.size(vm::TargetBytesPerWord), firstValue); - freezeSource( - c, firstValue->type.size(vm::TargetBytesPerWord), secondValue); - freezeSource(c, vm::TargetBytesPerWord, addressValue); + freezeSource(c, firstValue->type.size(c->targetInfo), firstValue); + freezeSource(c, firstValue->type.size(c->targetInfo), secondValue); + freezeSource(c, c->targetInfo.pointerSize, addressValue); apply(c, op, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), firstValue->source, firstValue->nextWord->source, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), secondValue->source, secondValue->nextWord->source, - vm::TargetBytesPerWord, + c->targetInfo.pointerSize, addressValue->source, addressValue->source); - thawSource(c, vm::TargetBytesPerWord, addressValue); - thawSource( - c, firstValue->type.size(vm::TargetBytesPerWord), secondValue); - thawSource( - c, firstValue->type.size(vm::TargetBytesPerWord), firstValue); + thawSource(c, c->targetInfo.pointerSize, addressValue); + thawSource(c, firstValue->type.size(c->targetInfo), secondValue); + thawSource(c, firstValue->type.size(c->targetInfo), firstValue); } } @@ -1648,11 +1675,11 @@ void appendBranch(Context* c, OperandMask secondMask; c->arch->planSource(op, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), firstMask, - firstValue->type.size(vm::TargetBytesPerWord), + firstValue->type.size(c->targetInfo), secondMask, - vm::TargetBytesPerWord, + c->targetInfo.pointerSize, &thunk); if (thunk) { @@ -1661,23 +1688,22 @@ void appendBranch(Context* c, size_t stackBase = c->stack ? c->stack->index + 1 : 0; bool threadParameter; - intptr_t handler - = c->client->getThunk(op, - firstValue->type.size(vm::TargetBytesPerWord), - firstValue->type.size(vm::TargetBytesPerWord), - &threadParameter); + intptr_t handler = c->client->getThunk(op, + firstValue->type.size(c->targetInfo), + firstValue->type.size(c->targetInfo), + &threadParameter); assert(c, not threadParameter); slicePush(c, - ceilingDivide(firstValue->type.size(vm::TargetBytesPerWord), - vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(c->targetInfo), + c->targetInfo.pointerSize), secondValue, stackBase, slice); slicePush(c, - ceilingDivide(firstValue->type.size(vm::TargetBytesPerWord), - vm::TargetBytesPerWord), + ceilingDivide(firstValue->type.size(c->targetInfo), + c->targetInfo.pointerSize), firstValue, stackBase, slice); @@ -1758,7 +1784,7 @@ class JumpEvent: public Event { { bool thunk; OperandMask mask; - c->arch->plan(op, vm::TargetBytesPerWord, mask, &thunk); + c->arch->plan(op, c->targetInfo.pointerSize, mask, &thunk); assert(c, not thunk); @@ -1771,7 +1797,7 @@ class JumpEvent: public Event { virtual void compile(Context* c) { if (not this->isUnreachable()) { - apply(c, op, vm::TargetBytesPerWord, address->source, address->source); + apply(c, op, c->targetInfo.pointerSize, address->source, address->source); } for (Read* r = reads; r; r = r->eventNext) { @@ -1832,17 +1858,26 @@ class BoundsCheckEvent: public Event { if (constant->value->value() < 0) { lir::Constant handlerConstant(resolvedPromise(c, handler)); a->apply(lir::Call, - OperandInfo(vm::TargetBytesPerWord, lir::ConstantOperand, &handlerConstant)); + OperandInfo(c->targetInfo.pointerSize, + lir::ConstantOperand, + &handlerConstant)); } } else { outOfBoundsPromise = compiler::codePromise(c, static_cast(0)); ConstantSite zero(resolvedPromise(c, 0)); ConstantSite oob(outOfBoundsPromise); - apply(c, lir::JumpIfLess, - 4, &zero, &zero, - 4, index->source, index->source, - vm::TargetBytesPerWord, &oob, &oob); + apply(c, + lir::JumpIfLess, + 4, + &zero, + &zero, + 4, + index->source, + index->source, + c->targetInfo.pointerSize, + &oob, + &oob); } if (constant == 0 or constant->value->value() >= 0) { @@ -1853,15 +1888,22 @@ class BoundsCheckEvent: public Event { CodePromise* nextPromise = compiler::codePromise(c, static_cast(0)); - freezeSource(c, vm::TargetBytesPerWord, index); + freezeSource(c, c->targetInfo.pointerSize, index); ConstantSite next(nextPromise); - apply(c, lir::JumpIfGreater, - 4, index->source, - index->source, 4, &length, - &length, vm::TargetBytesPerWord, &next, &next); + apply(c, + lir::JumpIfGreater, + 4, + index->source, + index->source, + 4, + &length, + &length, + c->targetInfo.pointerSize, + &next, + &next); - thawSource(c, vm::TargetBytesPerWord, index); + thawSource(c, c->targetInfo.pointerSize, index); if (constant == 0) { outOfBoundsPromise->offset = a->offset(); @@ -1869,7 +1911,9 @@ class BoundsCheckEvent: public Event { lir::Constant handlerConstant(resolvedPromise(c, handler)); a->apply(lir::Call, - OperandInfo(vm::TargetBytesPerWord, lir::ConstantOperand, &handlerConstant)); + OperandInfo(c->targetInfo.pointerSize, + lir::ConstantOperand, + &handlerConstant)); nextPromise->offset = a->offset(); } diff --git a/src/codegen/compiler/frame.cpp b/src/codegen/compiler/frame.cpp index f6a94f3b7a..223d036e9d 100644 --- a/src/codegen/compiler/frame.cpp +++ b/src/codegen/compiler/frame.cpp @@ -45,16 +45,18 @@ int frameIndex(Context* c, int localIndex) { unsigned frameIndexToOffset(Context* c, unsigned frameIndex) { assert(c, frameIndex < totalFrameSize(c)); - return (frameIndex + c->arch->frameFooterSize()) * vm::TargetBytesPerWord; + return (frameIndex + c->arch->frameFooterSize()) * c->targetInfo.pointerSize; } unsigned offsetToFrameIndex(Context* c, unsigned offset) { - assert(c, static_cast - ((offset / vm::TargetBytesPerWord) - c->arch->frameFooterSize()) >= 0); - assert(c, ((offset / vm::TargetBytesPerWord) - c->arch->frameFooterSize()) + assert(c, + static_cast((offset / c->targetInfo.pointerSize) + - c->arch->frameFooterSize()) >= 0); + assert(c, + ((offset / c->targetInfo.pointerSize) - c->arch->frameFooterSize()) < totalFrameSize(c)); - return (offset / vm::TargetBytesPerWord) - c->arch->frameFooterSize(); + return (offset / c->targetInfo.pointerSize) - c->arch->frameFooterSize(); } unsigned frameBase(Context* c) { diff --git a/src/codegen/compiler/promise.cpp b/src/codegen/compiler/promise.cpp index e3b5aa7247..1567140cca 100644 --- a/src/codegen/compiler/promise.cpp +++ b/src/codegen/compiler/promise.cpp @@ -90,9 +90,10 @@ class PoolPromise: public Promise { virtual int64_t value() { if (resolved()) { - return reinterpret_cast - (c->machineCode + vm::pad(c->machineCodeSize, vm::TargetBytesPerWord) - + (key * vm::TargetBytesPerWord)); + return reinterpret_cast( + c->machineCode + + vm::pad(c->machineCodeSize, c->targetInfo.pointerSize) + + (key * c->targetInfo.pointerSize)); } abort(c); diff --git a/src/codegen/compiler/site.cpp b/src/codegen/compiler/site.cpp index e5a1c02cb2..b1ddcee1d7 100644 --- a/src/codegen/compiler/site.cpp +++ b/src/codegen/compiler/site.cpp @@ -52,7 +52,7 @@ SiteIterator::SiteIterator(Context* c, Value* v, bool includeBuddies, Site** SiteIterator::findNext(Site** p) { while (true) { if (*p) { - if (pass == 0 or (*p)->registerSize(c) > vm::TargetBytesPerWord) { + if (pass == 0 or (*p)->registerSize(c) > c->targetInfo.pointerSize) { return p; } else { p = &((*p)->next); @@ -103,14 +103,11 @@ void SiteIterator::remove(Context* c) { previous = 0; } - - -unsigned Site::registerSize(Context*) { - return vm::TargetBytesPerWord; +unsigned Site::registerSize(Context* c) +{ + return c->targetInfo.pointerSize; } - - Site* constantSite(Context* c, Promise* value) { return new(c->zone) ConstantSite(value); } @@ -250,7 +247,7 @@ bool RegisterSite::matchNextWord(Context* c, Site* s, unsigned) { RegisterSite* rs = static_cast(s); unsigned size = rs->registerSize(c); - if (size > vm::TargetBytesPerWord) { + if (size > c->targetInfo.pointerSize) { assert(c, number != lir::NoRegister); return number == rs->number; } else { @@ -352,7 +349,7 @@ SiteMask RegisterSite::mask(Context* c UNUSED) { SiteMask RegisterSite::nextWordMask(Context* c, unsigned) { assert(c, number != lir::NoRegister); - if (registerSize(c) > vm::TargetBytesPerWord) { + if (registerSize(c) > c->targetInfo.pointerSize) { return SiteMask (1 << lir::RegisterOperand, number, NoFrameIndex); } else { @@ -367,7 +364,7 @@ unsigned RegisterSite::registerSize(Context* c) { if ((1 << number) & c->regFile->floatRegisters.mask) { return c->arch->floatRegisterSize(); } else { - return vm::TargetBytesPerWord; + return c->targetInfo.pointerSize; } } @@ -469,12 +466,15 @@ bool MemorySite::matchNextWord(Context* c, Site* s, unsigned index) { if (s->type(c) == lir::MemoryOperand) { MemorySite* ms = static_cast(s); return ms->base == this->base - and ((index == 1 and ms->offset == static_cast - (this->offset + vm::TargetBytesPerWord)) - or (index == 0 and this->offset == static_cast - (ms->offset + vm::TargetBytesPerWord))) - and ms->index == this->index - and ms->scale == this->scale; + and ((index == 1 + and ms->offset + == static_cast(this->offset + + c->targetInfo.pointerSize)) + or (index == 0 + and this->offset + == static_cast(ms->offset + + c->targetInfo.pointerSize))) + and ms->index == this->index and ms->scale == this->scale; } else { return false; } @@ -551,10 +551,11 @@ void MemorySite::asAssemblerOperand(Context* c UNUSED, Site* high UNUSED, lir::Operand* result) { // todo: endianness? - assert(c, high == this + assert(c, + high == this or (static_cast(high)->base == base and static_cast(high)->offset - == static_cast(offset + vm::TargetBytesPerWord) + == static_cast(offset + c->targetInfo.pointerSize) and static_cast(high)->index == index and static_cast(high)->scale == scale)); @@ -569,7 +570,8 @@ Site* MemorySite::copy(Context* c) { Site* MemorySite::copyHalf(Context* c, bool add) { if (add) { - return memorySite(c, base, offset + vm::TargetBytesPerWord, index, scale); + return memorySite( + c, base, offset + c->targetInfo.pointerSize, index, scale); } else { return copy(c); } @@ -584,10 +586,13 @@ Site* MemorySite::copyHigh(Context* c) { } Site* MemorySite::makeNextWord(Context* c, unsigned index) { - return memorySite - (c, base, offset + ((index == 1) xor c->arch->bigEndian() - ? vm::TargetBytesPerWord : -vm::TargetBytesPerWord), - this->index, scale); + return memorySite(c, + base, + offset + ((index == 1) xor c->arch->bigEndian() + ? c->targetInfo.pointerSize + : -c->targetInfo.pointerSize), + this->index, + scale); } SiteMask MemorySite::mask(Context* c) { diff --git a/src/codegen/compiler/value.cpp b/src/codegen/compiler/value.cpp index d04d2c6e0a..411cbe37ee 100644 --- a/src/codegen/compiler/value.cpp +++ b/src/codegen/compiler/value.cpp @@ -115,7 +115,8 @@ bool Value::uniqueSite(Context* c, Site* s) { if (it.hasMore()) { // the site is not this word's only site, but if the site is // shared with the next word, it may be that word's only site - if (this->nextWord != this and s->registerSize(c) > vm::TargetBytesPerWord) { + if (this->nextWord != this + and s->registerSize(c) > c->targetInfo.pointerSize) { SiteIterator nit(c, this->nextWord); Site* p = nit.next(); if (nit.hasMore()) { diff --git a/src/codegen/target/arm/assembler.cpp b/src/codegen/target/arm/assembler.cpp index db62aeef71..b817ef1ae2 100644 --- a/src/codegen/target/arm/assembler.cpp +++ b/src/codegen/target/arm/assembler.cpp @@ -180,6 +180,11 @@ class MyArchitecture: public Architecture { return 3; } + virtual ir::TargetInfo targetInfo() + { + return ir::TargetInfo(TargetBytesPerWord); + } + virtual bool bigEndian() { return false; } diff --git a/src/codegen/target/x86/assembler.cpp b/src/codegen/target/x86/assembler.cpp index 0614f21954..4791f65681 100644 --- a/src/codegen/target/x86/assembler.cpp +++ b/src/codegen/target/x86/assembler.cpp @@ -204,6 +204,11 @@ class MyArchitecture: public Architecture { return rdx; } + virtual ir::TargetInfo targetInfo() + { + return ir::TargetInfo(TargetBytesPerWord); + } + virtual bool bigEndian() { return false; } diff --git a/src/debug-util.cpp b/src/debug-util.cpp index 03a3c9540e..c0275aae97 100644 --- a/src/debug-util.cpp +++ b/src/debug-util.cpp @@ -446,12 +446,6 @@ int printInstruction(uint8_t* code, unsigned& ip, const char* prefix) fprintf( stderr, "lookupswitch default: %d pairCount: %d", default_, pairCount); - bool good = true; - if (pairCount >= 1000) { - pairCount = 1; - good = false; - } - for (int i = 0; i < pairCount; i++) { int32_t k = read32(code, ip); int32_t d = read32(code, ip) + startIp; @@ -459,8 +453,6 @@ int printInstruction(uint8_t* code, unsigned& ip, const char* prefix) } fprintf(stderr, "\n"); fflush(stderr); - if (!good) - asm("int3"); return 0; }