GBC Expander. Removed lir.

Change-Id: If8d13e36f1e6d82c2a7f7bfec62b8fb41fd8cdaa
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 7a6495a..4cfbdd3 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -26,6 +26,18 @@
 ART_USE_LLVM_COMPILER := true
 endif
 
+ART_USE_DEXLANG_FRONTEND := false
+ifeq ($(ART_USE_LLVM_COMPILER),true)
+  ifneq ($(wildcard art/USE_DEXLANG_FRONTEND),)
+  $(info Enabling ART_USE_DEXLANG_FRONTEND because of existence of art/USE_DEXLANG_FRONTEND)
+  ART_USE_DEXLANG_FRONTEND := true
+  endif
+  ifeq ($(WITH_ART_USE_DEXLANG_FRONTEND),true)
+  $(info Enabling ART_USE_DEXLANG_FRONTEND because WITH_ART_USE_DEXLANG_FRONTEND=true)
+  ART_USE_DEXLANG_FRONTEND := true
+  endif
+endif
+
 ART_USE_GREENLAND_COMPILER := false
 ifneq ($(wildcard art/USE_GREENLAND_COMPILER),)
 $(info Enabling ART_USE_GREENLAND_COMPILER because of existence of art/USE_GREENLAND_COMPILER)
@@ -254,7 +266,14 @@
 
 ifeq ($(ART_USE_GREENLAND_COMPILER),true)
 LIBART_COMMON_SRC_FILES += \
-	src/greenland/inferred_reg_category_map.cc
+	src/compiler_llvm/inferred_reg_category_map.cc \
+	src/greenland/runtime_entry_points.cc \
+	src/greenland/runtime/support_alloc.cc \
+	src/greenland/runtime/support_cast.cc \
+	src/greenland/runtime/support_dexcache.cc \
+	src/greenland/runtime/support_exception.cc \
+	src/greenland/runtime/support_field.cc \
+	src/greenland/runtime/support_thread.cc
 endif
 
 LIBART_COMMON_SRC_FILES += \
diff --git a/build/Android.executable.mk b/build/Android.executable.mk
index 3f0280b..ac1d64e 100644
--- a/build/Android.executable.mk
+++ b/build/Android.executable.mk
@@ -20,6 +20,9 @@
 ART_EXECUTABLES_CFLAGS :=
 ifeq ($(ART_USE_LLVM_COMPILER),true)
   ART_EXECUTABLES_CFLAGS += -DART_USE_LLVM_COMPILER=1
+  ifeq ($(ART_USE_DEXLANG_FRONTEND),true)
+    ART_EXECUTABLES_CFLAGS += -DART_USE_DEXLANG_FRONTEND=1
+  endif
 endif
 
 ifeq ($(ART_USE_GREENLAND_COMPILER),true)
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index cf98476..de8c502 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -22,6 +22,9 @@
 ART_TEST_CFLAGS :=
 ifeq ($(ART_USE_LLVM_COMPILER),true)
   ART_TEST_CFLAGS += -DART_USE_LLVM_COMPILER=1
+  ifeq ($(ART_USE_DEXLANG_FRONTEND),true)
+    ART_TEST_CFLAGS += -DART_USE_DEXLANG_FRONTEND=1
+  endif
 endif
 
 ifeq ($(ART_USE_GREENLAND_COMPILER),true)
diff --git a/build/Android.libart-compiler-greenland.mk b/build/Android.libart-compiler-greenland.mk
index c25ebd9..b999eff 100644
--- a/build/Android.libart-compiler-greenland.mk
+++ b/build/Android.libart-compiler-greenland.mk
@@ -18,16 +18,14 @@
 LIBART_COMPILER_GREENLAND_CFLAGS := -DART_USE_GREENLAND_COMPILER=1
 
 LIBART_COMPILER_GREENLAND_SRC_FILES += \
+	src/compiler_llvm/inferred_reg_category_map.cc \
 	src/greenland/dalvik_reg.cc \
 	src/greenland/dex_lang.cc \
+	src/greenland/gbc_context.cc \
 	src/greenland/greenland.cc \
-	src/greenland/lir.cc \
-	src/greenland/lir_function.cc \
-	src/greenland/inferred_reg_category_map.cc \
 	src/greenland/intrinsic_helper.cc \
-	src/greenland/ir_builder.cc \
+	src/greenland/register_allocator.cc \
 	src/greenland/target_codegen_machine.cc \
-	src/greenland/target_lir_emitter.cc \
 	src/greenland/target_registry.cc \
 	src/oat/jni/calling_convention.cc \
 	src/oat/jni/jni_compiler.cc \
@@ -49,6 +47,21 @@
   src/greenland/x86/x86_lir_info.cc \
   src/greenland/x86/x86_invoke_stub_compiler.cc
 
+########################################################################
+
+include $(CLEAR_VARS)
+LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
+LOCAL_MODULE := target_lir_builder_generator
+LOCAL_MODULE_TAGS := optional
+LOCAL_IS_HOST_MODULE := true
+LOCAL_SRC_FILES := src/greenland/tools/target_lir_builder_generator.cc
+LOCAL_CFLAGS := $(ART_HOST_CFLAGS) $(ART_HOST_DEBUG_CFLAGS)
+LOCAL_C_INCLUDES := $(ART_C_INCLUDES)
+include $(BUILD_HOST_EXECUTABLE)
+TARGET_LIR_BUILDER_GENERATOR := $(LOCAL_BUILT_MODULE)
+
+########################################################################
+
 # $(1): target or host
 # $(2): ndebug or debug
 define build-libart-compiler-greenland
@@ -85,21 +98,35 @@
   ifeq ($$(art_target_or_host),target)
     LOCAL_CFLAGS += $(ART_TARGET_CFLAGS)
   else # host
+    LOCAL_IS_HOST_MODULE := true
     LOCAL_CFLAGS += $(ART_HOST_CFLAGS)
   endif
 
   LOCAL_C_INCLUDES += $(ART_C_INCLUDES)
 
   ifeq ($$(art_target_or_host),target)
+    ENUM_INCLUDE_LIR_TARGETS := arm
     LOCAL_SRC_FILES += \
       $(LIBART_COMPILER_GREENLAND_$(TARGET_ARCH)_SRC_FILES)
   else
+    ENUM_INCLUDE_LIR_TARGETS := arm mips x86
     LOCAL_SRC_FILES += \
       $(LIBART_COMPILER_GREENLAND_arm_SRC_FILES) \
       $(LIBART_COMPILER_GREENLAND_mips_SRC_FILES) \
       $(LIBART_COMPILER_GREENLAND_x86_SRC_FILES)
   endif
 
+  GENERATED_SRC_DIR := $$(call intermediates-dir-for,$$(LOCAL_MODULE_CLASS),$$(LOCAL_MODULE),$$(LOCAL_IS_HOST_MODULE),)
+  ENUM_TARGEET_LIR_BUILDER_INC_FILES := $$(foreach lir_target, $$(ENUM_INCLUDE_LIR_TARGETS), $$(lir_target)_lir_builder_base.inc)
+  ENUM_TARGET_LIR_BUILDER_OUT_GEN := $$(addprefix $$(GENERATED_SRC_DIR)/, $$(ENUM_TARGEET_LIR_BUILDER_INC_FILES))
+
+$$(ENUM_TARGET_LIR_BUILDER_OUT_GEN): PRIVATE_LIR_TARGET = $$(subst _lir_builder_base.inc,,$$(notdir $$@))
+$$(ENUM_TARGET_LIR_BUILDER_OUT_GEN): %.inc : $$(TARGET_LIR_BUILDER_GENERATOR)
+	@echo "target Generated: $$@"
+	$$(hide) $$(TARGET_LIR_BUILDER_GENERATOR) $$(PRIVATE_LIR_TARGET) > $$@
+
+LOCAL_GENERATED_SOURCES += $$(ENUM_TARGET_LIR_BUILDER_OUT_GEN)
+
   LOCAL_STATIC_LIBRARIES += \
     libLLVMBitWriter \
     libLLVMBitReader \
@@ -114,7 +141,7 @@
   ifeq ($$(art_target_or_host),target)
     LOCAL_SHARED_LIBRARIES += libcutils libstlport libz libdl
     LOCAL_SHARED_LIBRARIES += libdynamic_annotations # tsan support
-#    LOCAL_SHARED_LIBRARIES += libcorkscrew # native stack trace support
+    LOCAL_SHARED_LIBRARIES += libcorkscrew # native stack trace support
   else # host
     LOCAL_STATIC_LIBRARIES += libcutils
     LOCAL_SHARED_LIBRARIES += libz-host
@@ -144,7 +171,6 @@
     include $(LLVM_DEVICE_BUILD_MK)
     include $(BUILD_SHARED_LIBRARY)
   else # host
-    LOCAL_IS_HOST_MODULE := true
     include $(LLVM_GEN_INTRINSICS_MK)
     include $(LLVM_HOST_BUILD_MK)
     include $(BUILD_HOST_SHARED_LIBRARY)
@@ -163,9 +189,9 @@
       $(HOST_OUT_EXECUTABLES)/dex2oat: $$(LOCAL_INSTALLED_MODULE)
     endif
   endif
-
 endef
 
+
 ifeq ($(ART_BUILD_TARGET_NDEBUG),true)
   $(eval $(call build-libart-compiler-greenland,target,ndebug))
 endif
diff --git a/build/Android.libart-compiler-llvm.mk b/build/Android.libart-compiler-llvm.mk
index 6e178d6..894fb54 100644
--- a/build/Android.libart-compiler-llvm.mk
+++ b/build/Android.libart-compiler-llvm.mk
@@ -16,16 +16,17 @@
 
 
 LIBART_COMPILER_LLVM_CFLAGS := -DART_USE_LLVM_COMPILER=1
+ifeq ($(ART_USE_DEXLANG_FRONTEND),true)
+  LIBART_COMPILER_LLVM_CFLAGS += -DART_USE_DEXLANG_FRONTEND=1
+endif
 
 LIBART_COMPILER_LLVM_SRC_FILES += \
 	src/compiler_llvm/compilation_unit.cc \
 	src/compiler_llvm/compiler_llvm.cc \
-	src/compiler_llvm/dalvik_reg.cc \
 	src/compiler_llvm/generated/art_module.cc \
 	src/compiler_llvm/inferred_reg_category_map.cc \
 	src/compiler_llvm/ir_builder.cc \
 	src/compiler_llvm/jni_compiler.cc \
-	src/compiler_llvm/method_compiler.cc \
 	src/compiler_llvm/runtime_support_builder.cc \
 	src/compiler_llvm/runtime_support_builder_arm.cc \
 	src/compiler_llvm/runtime_support_builder_thumb2.cc \
@@ -34,6 +35,19 @@
 	src/compiler_llvm/stub_compiler.cc \
 	src/compiler_llvm/tbaa_info.cc
 
+ifeq ($(ART_USE_DEXLANG_FRONTEND),true)
+  LIBART_COMPILER_LLVM_SRC_FILES += \
+    src/compiler_llvm/gbc_expander.cc \
+    src/greenland/dalvik_reg.cc \
+    src/greenland/dex_lang.cc \
+    src/greenland/intrinsic_helper.cc \
+    src/greenland/ir_builder.cc
+else
+  LIBART_COMPILER_LLVM_SRC_FILES += \
+	  src/compiler_llvm/dalvik_reg.cc \
+	  src/compiler_llvm/method_compiler.cc
+endif
+
 # $(1): target or host
 # $(2): ndebug or debug
 define build-libart-compiler-llvm
diff --git a/build/Android.libart.mk b/build/Android.libart.mk
index 9ccbe3f..6eaa778 100644
--- a/build/Android.libart.mk
+++ b/build/Android.libart.mk
@@ -17,6 +17,9 @@
 LIBART_CFLAGS :=
 ifeq ($(ART_USE_LLVM_COMPILER),true)
   LIBART_CFLAGS += -DART_USE_LLVM_COMPILER=1
+  ifeq ($(ART_USE_DEXLANG_FRONTEND),true)
+    LIBART_CFLAGS += -DART_USE_DEXLANG_FRONTEND=1
+  endif
 endif
 
 ifeq ($(ART_USE_GREENLAND_COMPILER),true)