From 4c8b593539dd927593a43f1e92f521addf33c8c9 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 23 Feb 2013 23:03:01 -0700 Subject: [PATCH] break Architecture out of Assembler --- include/avian/vm/codegen/architecture.h | 137 +++++++++++++++++++++++ include/avian/vm/codegen/assembler.h | 110 +----------------- include/avian/vm/codegen/targets.h | 14 ++- src/codegen/compiler.cpp | 1 + src/codegen/compiler/context.cpp | 2 + src/codegen/compiler/context.h | 2 +- src/codegen/compiler/frame.cpp | 2 + src/codegen/compiler/site.h | 2 + src/codegen/target/arm/assembler.cpp | 5 +- src/codegen/target/powerpc/assembler.cpp | 5 +- src/codegen/target/x86/assembler.cpp | 5 +- src/codegen/targets.cpp | 4 +- src/compile.cpp | 3 +- src/tools/audit-codegen/main.cpp | 2 +- unittest/codegen/assembler-test.cpp | 3 +- 15 files changed, 172 insertions(+), 125 deletions(-) create mode 100644 include/avian/vm/codegen/architecture.h diff --git a/include/avian/vm/codegen/architecture.h b/include/avian/vm/codegen/architecture.h new file mode 100644 index 0000000000..07c3fc5e35 --- /dev/null +++ b/include/avian/vm/codegen/architecture.h @@ -0,0 +1,137 @@ +/* Copyright (c) 2008-2012, 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_ARCHITECTURE_H +#define AVIAN_CODEGEN_ARCHITECTURE_H + +namespace vm { +class Allocator; +class Zone; +} + +namespace avian { +namespace codegen { + +class Assembler; + +class RegisterFile; + +class OperandMask { +public: + uint8_t typeMask; + uint64_t registerMask; + + OperandMask(uint8_t typeMask, uint64_t registerMask): + typeMask(typeMask), + registerMask(registerMask) + { } + + OperandMask(): + typeMask(~0), + registerMask(~static_cast(0)) + { } +}; + +class Architecture { +public: +virtual unsigned floatRegisterSize() = 0; + +virtual const RegisterFile* registerFile() = 0; + +virtual int scratch() = 0; +virtual int stack() = 0; +virtual int thread() = 0; +virtual int returnLow() = 0; +virtual int returnHigh() = 0; +virtual int virtualCallTarget() = 0; +virtual int virtualCallIndex() = 0; + +virtual bool bigEndian() = 0; + +virtual uintptr_t maximumImmediateJump() = 0; + +virtual bool alwaysCondensed(lir::BinaryOperation op) = 0; +virtual bool alwaysCondensed(lir::TernaryOperation op) = 0; + +virtual bool reserved(int register_) = 0; + +virtual unsigned frameFootprint(unsigned footprint) = 0; +virtual unsigned argumentFootprint(unsigned footprint) = 0; +virtual bool argumentAlignment() = 0; +virtual bool argumentRegisterAlignment() = 0; +virtual unsigned argumentRegisterCount() = 0; +virtual int argumentRegister(unsigned index) = 0; + +virtual bool hasLinkRegister() = 0; + +virtual unsigned stackAlignmentInWords() = 0; + +virtual bool matchCall(void* returnAddress, void* target) = 0; + +virtual void updateCall(lir::UnaryOperation op, void* returnAddress, + void* newTarget) = 0; + +virtual void setConstant(void* dst, uint64_t constant) = 0; + +virtual unsigned alignFrameSize(unsigned sizeInWords) = 0; + +virtual void nextFrame(void* start, unsigned size, unsigned footprint, + void* link, bool mostRecent, + unsigned targetParameterFootprint, void** ip, + void** stack) = 0; +virtual void* frameIp(void* stack) = 0; +virtual unsigned frameHeaderSize() = 0; +virtual unsigned frameReturnAddressSize() = 0; +virtual unsigned frameFooterSize() = 0; +virtual int returnAddressOffset() = 0; +virtual int framePointerOffset() = 0; + +virtual void plan +(lir::UnaryOperation op, + unsigned aSize, OperandMask& aMask, + bool* thunk) = 0; + +virtual void planSource +(lir::BinaryOperation op, + unsigned aSize, OperandMask& aMask, + unsigned bSize, bool* thunk) = 0; + +virtual void planDestination +(lir::BinaryOperation op, + unsigned aSize, const OperandMask& aMask, + unsigned bSize, OperandMask& bMask) = 0; + +virtual void planMove +(unsigned size, OperandMask& src, + OperandMask& tmp, + const OperandMask& dst) = 0; + +virtual void planSource +(lir::TernaryOperation op, + unsigned aSize, OperandMask& aMask, + unsigned bSize, OperandMask& bMask, + unsigned cSize, bool* thunk) = 0; + +virtual void planDestination +(lir::TernaryOperation op, + unsigned aSize, const OperandMask& aMask, + unsigned bSize, const OperandMask& bMask, + unsigned cSize, OperandMask& cMask) = 0; + +virtual Assembler* makeAssembler(vm::Allocator*, vm::Zone*) = 0; + +virtual void acquire() = 0; +virtual void release() = 0; +}; + +} // namespace codegen +} // namespace avian + +#endif // AVIAN_CODEGEN_ARCHITECTURE_H \ No newline at end of file diff --git a/include/avian/vm/codegen/assembler.h b/include/avian/vm/codegen/assembler.h index 6f370cbe3c..8c18176892 100644 --- a/include/avian/vm/codegen/assembler.h +++ b/include/avian/vm/codegen/assembler.h @@ -20,7 +20,7 @@ namespace avian { namespace codegen { -class RegisterFile; +class Architecture; class OperandInfo { public: @@ -35,22 +35,6 @@ public: { } }; -class OperandMask { -public: - uint8_t typeMask; - uint64_t registerMask; - - OperandMask(uint8_t typeMask, uint64_t registerMask): - typeMask(typeMask), - registerMask(registerMask) - { } - - OperandMask(): - typeMask(~0), - registerMask(~static_cast(0)) - { } -}; - #ifdef AVIAN_TAILS const bool TailCalls = true; #else @@ -80,98 +64,6 @@ class Assembler { virtual unsigned resolve(unsigned start, Block* next) = 0; }; - class Architecture { - public: - virtual unsigned floatRegisterSize() = 0; - - virtual const RegisterFile* registerFile() = 0; - - virtual int scratch() = 0; - virtual int stack() = 0; - virtual int thread() = 0; - virtual int returnLow() = 0; - virtual int returnHigh() = 0; - virtual int virtualCallTarget() = 0; - virtual int virtualCallIndex() = 0; - - virtual bool bigEndian() = 0; - - virtual uintptr_t maximumImmediateJump() = 0; - - virtual bool alwaysCondensed(lir::BinaryOperation op) = 0; - virtual bool alwaysCondensed(lir::TernaryOperation op) = 0; - - virtual bool reserved(int register_) = 0; - - virtual unsigned frameFootprint(unsigned footprint) = 0; - virtual unsigned argumentFootprint(unsigned footprint) = 0; - virtual bool argumentAlignment() = 0; - virtual bool argumentRegisterAlignment() = 0; - virtual unsigned argumentRegisterCount() = 0; - virtual int argumentRegister(unsigned index) = 0; - - virtual bool hasLinkRegister() = 0; - - virtual unsigned stackAlignmentInWords() = 0; - - virtual bool matchCall(void* returnAddress, void* target) = 0; - - virtual void updateCall(lir::UnaryOperation op, void* returnAddress, - void* newTarget) = 0; - - virtual void setConstant(void* dst, uint64_t constant) = 0; - - virtual unsigned alignFrameSize(unsigned sizeInWords) = 0; - - virtual void nextFrame(void* start, unsigned size, unsigned footprint, - void* link, bool mostRecent, - unsigned targetParameterFootprint, void** ip, - void** stack) = 0; - virtual void* frameIp(void* stack) = 0; - virtual unsigned frameHeaderSize() = 0; - virtual unsigned frameReturnAddressSize() = 0; - virtual unsigned frameFooterSize() = 0; - virtual int returnAddressOffset() = 0; - virtual int framePointerOffset() = 0; - - virtual void plan - (lir::UnaryOperation op, - unsigned aSize, OperandMask& aMask, - bool* thunk) = 0; - - virtual void planSource - (lir::BinaryOperation op, - unsigned aSize, OperandMask& aMask, - unsigned bSize, bool* thunk) = 0; - - virtual void planDestination - (lir::BinaryOperation op, - unsigned aSize, const OperandMask& aMask, - unsigned bSize, OperandMask& bMask) = 0; - - virtual void planMove - (unsigned size, OperandMask& src, - OperandMask& tmp, - const OperandMask& dst) = 0; - - virtual void planSource - (lir::TernaryOperation op, - unsigned aSize, OperandMask& aMask, - unsigned bSize, OperandMask& bMask, - unsigned cSize, bool* thunk) = 0; - - virtual void planDestination - (lir::TernaryOperation op, - unsigned aSize, const OperandMask& aMask, - unsigned bSize, const OperandMask& bMask, - unsigned cSize, OperandMask& cMask) = 0; - - virtual Assembler* makeAssembler(vm::Allocator*, vm::Zone*) = 0; - - virtual void acquire() = 0; - virtual void release() = 0; - }; - virtual void setClient(Client* client) = 0; virtual Architecture* arch() = 0; diff --git a/include/avian/vm/codegen/targets.h b/include/avian/vm/codegen/targets.h index e3ffbd981a..a8adb246ce 100644 --- a/include/avian/vm/codegen/targets.h +++ b/include/avian/vm/codegen/targets.h @@ -11,16 +11,20 @@ #ifndef AVIAN_CODEGEN_TARGETS_H #define AVIAN_CODEGEN_TARGETS_H -#include +namespace vm { +class System; +} namespace avian { namespace codegen { -Assembler::Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures); +class Architecture; -Assembler::Architecture* makeArchitectureX86(vm::System* system, bool useNativeFeatures); -Assembler::Architecture* makeArchitectureArm(vm::System* system, bool useNativeFeatures); -Assembler::Architecture* makeArchitecturePowerpc(vm::System* system, bool useNativeFeatures); +Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures); + +Architecture* makeArchitectureX86(vm::System* system, bool useNativeFeatures); +Architecture* makeArchitectureArm(vm::System* system, bool useNativeFeatures); +Architecture* makeArchitecturePowerpc(vm::System* system, bool useNativeFeatures); } // namespace codegen } // namespace avian diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 1985629cfb..a093c1f5bf 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include "codegen/compiler/regalloc.h" diff --git a/src/codegen/compiler/context.cpp b/src/codegen/compiler/context.cpp index dd1f129bad..5d77fdcd77 100644 --- a/src/codegen/compiler/context.cpp +++ b/src/codegen/compiler/context.cpp @@ -11,6 +11,8 @@ #include "codegen/compiler/context.h" #include "codegen/compiler/resource.h" +#include + namespace avian { namespace codegen { namespace compiler { diff --git a/src/codegen/compiler/context.h b/src/codegen/compiler/context.h index d9894eda8c..cd19097c42 100644 --- a/src/codegen/compiler/context.h +++ b/src/codegen/compiler/context.h @@ -75,7 +75,7 @@ class Context { vm::System* system; Assembler* assembler; - Assembler::Architecture* arch; + Architecture* arch; vm::Zone* zone; Compiler::Client* client; Stack* stack; diff --git a/src/codegen/compiler/frame.cpp b/src/codegen/compiler/frame.cpp index e879238b79..cae48b9fee 100644 --- a/src/codegen/compiler/frame.cpp +++ b/src/codegen/compiler/frame.cpp @@ -13,6 +13,8 @@ #include "codegen/compiler/context.h" #include "codegen/compiler/frame.h" +#include + namespace avian { namespace codegen { namespace compiler { diff --git a/src/codegen/compiler/site.h b/src/codegen/compiler/site.h index bf2cef34b6..aedcc7ab09 100644 --- a/src/codegen/compiler/site.h +++ b/src/codegen/compiler/site.h @@ -11,6 +11,8 @@ #ifndef AVIAN_CODEGEN_COMPILER_SITE_H #define AVIAN_CODEGEN_COMPILER_SITE_H +#include + #include "codegen/compiler/value.h" #include "codegen/compiler/context.h" diff --git a/src/codegen/target/arm/assembler.cpp b/src/codegen/target/arm/assembler.cpp index 511f7ccc32..8be76085e1 100644 --- a/src/codegen/target/arm/assembler.cpp +++ b/src/codegen/target/arm/assembler.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include "context.h" @@ -136,7 +137,7 @@ nextFrame(ArchitectureContext* con, uint32_t* start, unsigned size UNUSED, *stack = static_cast(*stack) + offset; } -class MyArchitecture: public Assembler::Architecture { +class MyArchitecture: public Architecture { public: MyArchitecture(System* system): con(system), referenceCount(0) { populateTables(&con); @@ -950,7 +951,7 @@ Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) { } // namespace arm -Assembler::Architecture* +Architecture* makeArchitectureArm(System* system, bool) { return new (allocate(system, sizeof(arm::MyArchitecture))) arm::MyArchitecture(system); diff --git a/src/codegen/target/powerpc/assembler.cpp b/src/codegen/target/powerpc/assembler.cpp index cda4fdbc96..5ad517871a 100644 --- a/src/codegen/target/powerpc/assembler.cpp +++ b/src/codegen/target/powerpc/assembler.cpp @@ -9,6 +9,7 @@ details. */ #include +#include #include #include "alloc-vector.h" @@ -235,7 +236,7 @@ nextFrame(ArchitectureContext* c UNUSED, int32_t* start, unsigned size, *stack = static_cast(*stack) + offset; } -class MyArchitecture: public Assembler::Architecture { +class MyArchitecture: public Architecture { public: MyArchitecture(System* system): c(system), referenceCount(0) { populateTables(&c); @@ -996,7 +997,7 @@ Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) { } // namespace powerpc -Assembler::Architecture* +Architecture* makeArchitecturePowerpc(System* system, bool) { return new (allocate(system, sizeof(powerpc::MyArchitecture))) powerpc::MyArchitecture(system); diff --git a/src/codegen/target/x86/assembler.cpp b/src/codegen/target/x86/assembler.cpp index a568430f91..6b1a1679ad 100644 --- a/src/codegen/target/x86/assembler.cpp +++ b/src/codegen/target/x86/assembler.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -147,7 +148,7 @@ nextFrame(ArchitectureContext* c UNUSED, uint8_t* start, unsigned size UNUSED, *stack = static_cast(*stack) + offset; } -class MyArchitecture: public Assembler::Architecture { +class MyArchitecture: public Architecture { public: MyArchitecture(System* system, bool useNativeFeatures): c(system, useNativeFeatures), @@ -1148,7 +1149,7 @@ Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) { } // namespace x86 -Assembler::Architecture* makeArchitectureX86(System* system, bool useNativeFeatures) +Architecture* makeArchitectureX86(System* system, bool useNativeFeatures) { return new (allocate(system, sizeof(x86::MyArchitecture))) x86::MyArchitecture(system, useNativeFeatures); diff --git a/src/codegen/targets.cpp b/src/codegen/targets.cpp index 4b9d44fc7e..af8f66219c 100644 --- a/src/codegen/targets.cpp +++ b/src/codegen/targets.cpp @@ -8,6 +8,8 @@ There is NO WARRANTY for this software. See license.txt for details. */ +#include "common.h" + #include #include "environment.h" @@ -15,7 +17,7 @@ namespace avian { namespace codegen { -Assembler::Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures UNUSED) { +Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures UNUSED) { #ifndef AVIAN_TARGET_ARCH #error "Must specify native target!" #endif diff --git a/src/compile.cpp b/src/compile.cpp index 02a87cd4c8..b19b45ca7e 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -16,6 +16,7 @@ #include "arch.h" #include +#include #include #include @@ -294,7 +295,7 @@ class MyThread: public Thread { void** thunkTable; CallTrace* trace; Reference* reference; - avian::codegen::Assembler::Architecture* arch; + avian::codegen::Architecture* arch; Context* transition; TraceContext* traceContext; uintptr_t stackLimit; diff --git a/src/tools/audit-codegen/main.cpp b/src/tools/audit-codegen/main.cpp index d201cd43a4..5cc7d79709 100644 --- a/src/tools/audit-codegen/main.cpp +++ b/src/tools/audit-codegen/main.cpp @@ -31,7 +31,7 @@ class BasicEnv { public: System* s; Heap* heap; - Assembler::Architecture* arch; + Architecture* arch; BasicEnv(): s(makeSystem(0)), diff --git a/unittest/codegen/assembler-test.cpp b/unittest/codegen/assembler-test.cpp index dde1b1b074..0412766b59 100644 --- a/unittest/codegen/assembler-test.cpp +++ b/unittest/codegen/assembler-test.cpp @@ -16,6 +16,7 @@ #include "target.h" #include +#include #include #include @@ -29,7 +30,7 @@ class BasicEnv { public: System* s; Heap* heap; - Assembler::Architecture* arch; + Architecture* arch; BasicEnv(): s(makeSystem(0)),