From f7b49ddb06cf7d24c9a9622c11076fa68e3b32db Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Tue, 12 Feb 2013 08:15:30 -0700 Subject: [PATCH] allow codegen targets (Architectures and Assemblers) to co-exist The primary motivation behind this is to allow all the different Assemblers to be built at once, on a single machine. This should dramatically reduce the time required to make sure that a particular change doesn't break the build for one of the not-so-common architectures (arm, powerpc) Simply pass "codegen-targets=all" to make to compile all src/codegen//assembler.cpp. Note that while these architectures are built, they will not be fully- functional. Certain stuff is assumed to be the same across the entire build (such as TargetBytesPerWord), but this isn't the case anymore. --- makefile | 18 ++++++++++++++- src/codegen/arm/assembler.cpp | 24 ++++++++++---------- src/codegen/assembler.h | 11 +++------ src/codegen/powerpc/assembler.cpp | 25 ++++++++++----------- src/codegen/targets.cpp | 37 +++++++++++++++++++++++++++++++ src/codegen/targets.h | 28 +++++++++++++++++++++++ src/codegen/x86/assembler.cpp | 25 ++++++++++----------- src/compile.cpp | 7 +++--- 8 files changed, 125 insertions(+), 50 deletions(-) create mode 100644 src/codegen/targets.cpp create mode 100644 src/codegen/targets.h diff --git a/makefile b/makefile index bdce03c7c3..e679fd7d97 100755 --- a/makefile +++ b/makefile @@ -25,6 +25,8 @@ bootimage-platform = \ $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) platform = $(bootimage-platform) +codegen-targets = native + mode = fast process = compile @@ -49,6 +51,9 @@ endif ifeq ($(continuations),true) options := $(options)-continuations endif +ifeq ($(codegen-targets),all) + options := $(options)-all +endif root := $(shell (cd .. && pwd)) build = build/$(platform)-$(arch)$(options) @@ -659,7 +664,18 @@ embed-objects = $(call cpp-objects,$(embed-sources),$(src),$(build-embed)) ifeq ($(process),compile) vm-sources += \ $(src)/codegen/compiler.cpp \ - $(src)/codegen/$(target-asm)/assembler.cpp + $(src)/codegen/targets.cpp + + ifeq ($(codegen-targets),native) + vm-sources += \ + $(src)/codegen/$(target-asm)/assembler.cpp + endif + ifeq ($(codegen-targets),all) + vm-sources += \ + $(src)/codegen/x86/assembler.cpp \ + $(src)/codegen/arm/assembler.cpp \ + $(src)/codegen/powerpc/assembler.cpp + endif vm-asm-sources += $(src)/compile-$(asm).S endif diff --git a/src/codegen/arm/assembler.cpp b/src/codegen/arm/assembler.cpp index e0e3751839..bb7328726e 100644 --- a/src/codegen/arm/assembler.cpp +++ b/src/codegen/arm/assembler.cpp @@ -8,7 +8,7 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include "assembler.h" +#include "codegen/assembler.h" #include "alloc-vector.h" #define CAST1(x) reinterpret_cast(x) @@ -2500,6 +2500,8 @@ class MyArchitecture: public Assembler::Architecture { } } + virtual Assembler* makeAssembler(Allocator* allocator, Zone* zone); + virtual void acquire() { ++ referenceCount; } @@ -2896,22 +2898,20 @@ class MyAssembler: public Assembler { MyArchitecture* arch_; }; +Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) { + return new(zone) MyAssembler(this->con.s, allocator, zone, this); +} + } // namespace -namespace vm { +namespace avian { +namespace codegen { Assembler::Architecture* -makeArchitecture(System* system, bool) +makeArchitectureArm(System* system, bool) { return new (allocate(system, sizeof(MyArchitecture))) MyArchitecture(system); } -Assembler* -makeAssembler(System* system, Allocator* allocator, Zone* zone, - Assembler::Architecture* architecture) -{ - return new(zone) MyAssembler(system, allocator, zone, - static_cast(architecture)); -} - -} // namespace vm +} // namespace codegen +} // namespace avian diff --git a/src/codegen/assembler.h b/src/codegen/assembler.h index d2ba2caf5d..fbe03b70ac 100644 --- a/src/codegen/assembler.h +++ b/src/codegen/assembler.h @@ -408,7 +408,9 @@ class Assembler { (TernaryOperation op, unsigned aSize, uint8_t aTypeMask, uint64_t aRegisterMask, unsigned bSize, uint8_t bTypeMask, uint64_t bRegisterMask, - unsigned cSize, uint8_t* cTypeMask, uint64_t* cRegisterMask) = 0; + unsigned cSize, uint8_t* cTypeMask, uint64_t* cRegisterMask) = 0; + + virtual Assembler* makeAssembler(Allocator*, Zone*) = 0; virtual void acquire() = 0; virtual void release() = 0; @@ -466,13 +468,6 @@ class Assembler { virtual void dispose() = 0; }; -Assembler::Architecture* -makeArchitecture(System* system, bool useNativeFeatures); - -Assembler* -makeAssembler(System* system, Allocator* allocator, Zone* zone, - Assembler::Architecture* architecture); - } // namespace vm #endif//ASSEMBLER_H diff --git a/src/codegen/powerpc/assembler.cpp b/src/codegen/powerpc/assembler.cpp index d70cb36bef..415ef3fa54 100644 --- a/src/codegen/powerpc/assembler.cpp +++ b/src/codegen/powerpc/assembler.cpp @@ -8,7 +8,7 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include "assembler.h" +#include "codegen/assembler.h" #include "alloc-vector.h" #define CAST1(x) reinterpret_cast(x) @@ -2446,6 +2446,8 @@ class MyArchitecture: public Assembler::Architecture { } } + virtual Assembler* makeAssembler(Allocator* allocator, Zone* zone); + virtual void acquire() { ++ referenceCount; } @@ -2858,23 +2860,20 @@ class MyAssembler: public Assembler { MyArchitecture* arch_; }; +Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) { + return new(zone) MyAssembler(this->c.s, allocator, zone, this); +} + } // namespace -namespace vm { +namespace avian { +namespace codegen { Assembler::Architecture* -makeArchitecture(System* system, bool) +makeArchitecturePowerpc(System* system, bool) { return new (allocate(system, sizeof(MyArchitecture))) MyArchitecture(system); } -Assembler* -makeAssembler(System* system, Allocator* allocator, Zone* zone, - Assembler::Architecture* architecture) -{ - return - new(zone) MyAssembler(system, allocator, zone, - static_cast(architecture)); -} - -} // namespace vm +} // namespace codegen +} // namespace avian diff --git a/src/codegen/targets.cpp b/src/codegen/targets.cpp new file mode 100644 index 0000000000..64b5a0f630 --- /dev/null +++ b/src/codegen/targets.cpp @@ -0,0 +1,37 @@ +/* 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. */ + +#include "codegen/targets.h" +#include "environment.h" + +namespace avian { +namespace codegen { + +vm::Assembler::Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures UNUSED) { +#ifndef AVIAN_TARGET_ARCH + #error "Must specify native target!" +#endif + +#if AVIAN_TARGET_ARCH == AVIAN_ARCH_UNKNOWN + system->abort(); + return 0; +#elif (AVIAN_TARGET_ARCH == AVIAN_ARCH_X86) || (AVIAN_TARGET_ARCH == AVIAN_ARCH_X86_64) + return makeArchitectureX86(system, useNativeFeatures); +#elif AVIAN_TARGET_ARCH == AVIAN_ARCH_ARM + return makeArchitectureArm(system, useNativeFeatures); +#elif AVIAN_TARGET_ARCH == AVIAN_ARCH_POWERPC + return makeArchitecturePowerpc(system, useNativeFeatures); +#else + #error "Unsupported codegen target" +#endif +} + +} // namespace codegen +} // namespace avian diff --git a/src/codegen/targets.h b/src/codegen/targets.h new file mode 100644 index 0000000000..c4070b4641 --- /dev/null +++ b/src/codegen/targets.h @@ -0,0 +1,28 @@ +/* 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_TARGETS_H +#define AVIAN_CODEGEN_TARGETS_H + +#include "codegen/assembler.h" + +namespace avian { +namespace codegen { + +vm::Assembler::Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures); + +vm::Assembler::Architecture* makeArchitectureX86(vm::System* system, bool useNativeFeatures); +vm::Assembler::Architecture* makeArchitectureArm(vm::System* system, bool useNativeFeatures); +vm::Assembler::Architecture* makeArchitecturePowerpc(vm::System* system, bool useNativeFeatures); + +} // namespace codegen +} // namespace avian + +#endif // AVIAN_CODEGEN_TARGETS_H diff --git a/src/codegen/x86/assembler.cpp b/src/codegen/x86/assembler.cpp index 4270207eea..e1f107dc32 100644 --- a/src/codegen/x86/assembler.cpp +++ b/src/codegen/x86/assembler.cpp @@ -3387,6 +3387,8 @@ class MyArchitecture: public Assembler::Architecture { } } + virtual Assembler* makeAssembler(Allocator* allocator, Zone* zone); + virtual void acquire() { ++ referenceCount; } @@ -3732,26 +3734,23 @@ class MyAssembler: public Assembler { MyArchitecture* arch_; }; +Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) { + return + new(zone) MyAssembler(c.s, allocator, zone, this); +} + } // namespace local } // namespace -namespace vm { +namespace avian { +namespace codegen { -Assembler::Architecture* -makeArchitecture(System* system, bool useNativeFeatures) +Assembler::Architecture* makeArchitectureX86(System* system, bool useNativeFeatures) { return new (allocate(system, sizeof(local::MyArchitecture))) local::MyArchitecture(system, useNativeFeatures); } -Assembler* -makeAssembler(System* system, Allocator* allocator, Zone* zone, - Assembler::Architecture* architecture) -{ - return - new(zone) local::MyAssembler(system, allocator, zone, - static_cast(architecture)); -} - -} // namespace vm +} // namespace codegen +} // namespace avian diff --git a/src/compile.cpp b/src/compile.cpp index 1a17e62e1b..bae11823d5 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -15,6 +15,7 @@ #include "target.h" #include "codegen/assembler.h" #include "codegen/compiler.h" +#include "codegen/targets.h" #include "arch.h" #include "util/runtime-array.h" @@ -264,7 +265,7 @@ class MyThread: public Thread { reference(0), arch(parent ? parent->arch - : makeArchitecture(m->system, useNativeFeatures)), + : avian::codegen::makeArchitectureNative(m->system, useNativeFeatures)), transition(0), traceContext(0), stackLimit(0), @@ -1225,7 +1226,7 @@ class Context { Context(MyThread* t, BootContext* bootContext, object method): thread(t), zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), - assembler(makeAssembler(t->m->system, t->m->heap, &zone, t->arch)), + assembler(t->arch->makeAssembler(t->m->heap, &zone)), client(t), compiler(makeCompiler(t->m->system, assembler, &zone, &client)), method(method), @@ -1251,7 +1252,7 @@ class Context { Context(MyThread* t): thread(t), zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), - assembler(makeAssembler(t->m->system, t->m->heap, &zone, t->arch)), + assembler(t->arch->makeAssembler(t->m->heap, &zone)), client(t), compiler(0), method(0),