diff options
author | Dan Gohman <sunfish@mozilla.com> | 2014-03-04 12:54:43 -0800 |
---|---|---|
committer | Dan Gohman <sunfish@mozilla.com> | 2014-03-04 13:08:47 -0800 |
commit | dc1378e24ff461546f531ec3a6138046b8e9c9ef (patch) | |
tree | 11d7f7e71f144b0c2dfa90a2e1e88a9ae3a6b702 /lib | |
parent | 65405351ba0b32a8658c65940e0b65ceb2601ad4 (diff) |
Better integration with the LLVM Target system.
In particular, this is needed to make getOptLevel() work.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/JSBackend/CMakeLists.txt | 2 | ||||
-rw-r--r-- | lib/Target/JSBackend/JSBackend.cpp | 2 | ||||
-rw-r--r-- | lib/Target/JSBackend/JSTargetMachine.cpp | 14 | ||||
-rw-r--r-- | lib/Target/JSBackend/JSTargetMachine.h | 17 | ||||
-rw-r--r-- | lib/Target/JSBackend/LLVMBuild.txt | 2 | ||||
-rw-r--r-- | lib/Target/JSBackend/MCTargetDesc/CMakeLists.txt | 8 | ||||
-rw-r--r-- | lib/Target/JSBackend/MCTargetDesc/JSBackendMCTargetDesc.cpp | 31 | ||||
-rw-r--r-- | lib/Target/JSBackend/MCTargetDesc/JSBackendMCTargetDesc.h | 25 | ||||
-rw-r--r-- | lib/Target/JSBackend/MCTargetDesc/LLVMBuild.txt | 23 | ||||
-rw-r--r-- | lib/Target/JSBackend/MCTargetDesc/Makefile | 16 | ||||
-rw-r--r-- | lib/Target/JSBackend/Makefile | 2 | ||||
-rw-r--r-- | lib/Target/JSBackend/OptPasses.h | 2 | ||||
-rw-r--r-- | lib/Target/JSBackend/SimplifyAllocas.cpp | 29 | ||||
-rw-r--r-- | lib/Target/JSBackend/TargetInfo/JSBackendTargetInfo.cpp | 20 |
14 files changed, 158 insertions, 35 deletions
diff --git a/lib/Target/JSBackend/CMakeLists.txt b/lib/Target/JSBackend/CMakeLists.txt index 37704f316f..a80e23050a 100644 --- a/lib/Target/JSBackend/CMakeLists.txt +++ b/lib/Target/JSBackend/CMakeLists.txt @@ -1,8 +1,10 @@ add_llvm_target(JSBackendCodeGen ExpandI64.cpp JSBackend.cpp + JSTargetMachine.cpp Relooper.cpp SimplifyAllocas.cpp ) add_subdirectory(TargetInfo) +add_subdirectory(MCTargetDesc) diff --git a/lib/Target/JSBackend/JSBackend.cpp b/lib/Target/JSBackend/JSBackend.cpp index 6ed2632441..f1a6aa59ee 100644 --- a/lib/Target/JSBackend/JSBackend.cpp +++ b/lib/Target/JSBackend/JSBackend.cpp @@ -15,6 +15,7 @@ //===----------------------------------------------------------------------===// #include "JSTargetMachine.h" +#include "MCTargetDesc/JSBackendMCTargetDesc.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" @@ -2350,4 +2351,3 @@ bool JSTargetMachine::addPassesToEmitFile(PassManagerBase &PM, return false; } - diff --git a/lib/Target/JSBackend/JSTargetMachine.cpp b/lib/Target/JSBackend/JSTargetMachine.cpp new file mode 100644 index 0000000000..af428f2eb2 --- /dev/null +++ b/lib/Target/JSBackend/JSTargetMachine.cpp @@ -0,0 +1,14 @@ +#include "JSTargetMachine.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/PassManager.h" +using namespace llvm; + +JSTargetMachine::JSTargetMachine(const Target &T, StringRef Triple, + StringRef CPU, StringRef FS, const TargetOptions &Options, + Reloc::Model RM, CodeModel::Model CM, + CodeGenOpt::Level OL) + : TargetMachine(T, Triple, CPU, FS, Options), + DL("e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" + "f32:32:32-f64:64:64-p:32:32:32-v128:32:128-n32-S128") { + CodeGenInfo = T.createMCCodeGenInfo(Triple, RM, CM, OL); +} diff --git a/lib/Target/JSBackend/JSTargetMachine.h b/lib/Target/JSBackend/JSTargetMachine.h index b11533d692..3912d3b5b2 100644 --- a/lib/Target/JSBackend/JSTargetMachine.h +++ b/lib/Target/JSBackend/JSTargetMachine.h @@ -1,4 +1,4 @@ -//===-- JSTargetMachine.h - TargetMachine for the C++ backend --*- C++ -*-===// +//===-- JSTargetMachine.h - TargetMachine for the JS Backend ----*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -22,12 +22,14 @@ namespace llvm { class formatted_raw_ostream; -struct JSTargetMachine : public TargetMachine { - JSTargetMachine(const Target &T, StringRef TT, +class JSTargetMachine : public TargetMachine { + const DataLayout DL; + +public: + JSTargetMachine(const Target &T, StringRef Triple, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, - CodeGenOpt::Level OL) - : TargetMachine(T, TT, CPU, FS, Options) {} + CodeGenOpt::Level OL); virtual bool addPassesToEmitFile(PassManagerBase &PM, formatted_raw_ostream &Out, @@ -36,12 +38,9 @@ struct JSTargetMachine : public TargetMachine { AnalysisID StartAfter, AnalysisID StopAfter); - virtual const DataLayout *getDataLayout() const { return 0; } + virtual const DataLayout *getDataLayout() const { return &DL; } }; -extern Target TheJSBackendTarget; - } // End llvm namespace - #endif diff --git a/lib/Target/JSBackend/LLVMBuild.txt b/lib/Target/JSBackend/LLVMBuild.txt index 33b433bfb7..a432481007 100644 --- a/lib/Target/JSBackend/LLVMBuild.txt +++ b/lib/Target/JSBackend/LLVMBuild.txt @@ -16,7 +16,7 @@ ;===------------------------------------------------------------------------===; [common] -subdirectories = TargetInfo +subdirectories = MCTargetDesc TargetInfo [component_0] type = TargetGroup diff --git a/lib/Target/JSBackend/MCTargetDesc/CMakeLists.txt b/lib/Target/JSBackend/MCTargetDesc/CMakeLists.txt new file mode 100644 index 0000000000..0af77f5595 --- /dev/null +++ b/lib/Target/JSBackend/MCTargetDesc/CMakeLists.txt @@ -0,0 +1,8 @@ +add_llvm_library(LLVMJSBackendDesc + JSBackendMCTargetDesc.cpp + ) + +add_dependencies(LLVMJSBackendDesc) + +# Hack: we need to include 'main' target directory to grab private headers +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/..) diff --git a/lib/Target/JSBackend/MCTargetDesc/JSBackendMCTargetDesc.cpp b/lib/Target/JSBackend/MCTargetDesc/JSBackendMCTargetDesc.cpp new file mode 100644 index 0000000000..f7ba068683 --- /dev/null +++ b/lib/Target/JSBackend/MCTargetDesc/JSBackendMCTargetDesc.cpp @@ -0,0 +1,31 @@ +//===-- JSBackendMCTargetDesc.cpp - JS Backend Target Descriptions --------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides asm.js specific target descriptions. +// +//===----------------------------------------------------------------------===// + +#include "JSBackendMCTargetDesc.h" +#include "llvm/MC/MCCodeGenInfo.h" +#include "llvm/Support/TargetRegistry.h" +using namespace llvm; + +static MCCodeGenInfo *createJSBackendMCCodeGenInfo(StringRef Triple, Reloc::Model RM, + CodeModel::Model CM, + CodeGenOpt::Level OL) { + MCCodeGenInfo *X = new MCCodeGenInfo(); + X->InitMCCodeGenInfo(RM, CM, OL); + return X; +} + +// Force static initialization. +extern "C" void LLVMInitializeJSBackendTargetMC() { + // Register the MC codegen info. + RegisterMCCodeGenInfoFn C(TheJSBackendTarget, createJSBackendMCCodeGenInfo); +} diff --git a/lib/Target/JSBackend/MCTargetDesc/JSBackendMCTargetDesc.h b/lib/Target/JSBackend/MCTargetDesc/JSBackendMCTargetDesc.h new file mode 100644 index 0000000000..c98a55df83 --- /dev/null +++ b/lib/Target/JSBackend/MCTargetDesc/JSBackendMCTargetDesc.h @@ -0,0 +1,25 @@ +//===- JSBackendMCTargetDesc.h - JS Backend Target Descriptions -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides asm.js specific target descriptions. +// +//===----------------------------------------------------------------------===// + +#ifndef JSBACKENDMCTARGETDESC_H +#define JSBACKENDMCTARGETDESC_H + +#include "llvm/Support/TargetRegistry.h" + +namespace llvm { + +extern Target TheJSBackendTarget; + +} // End llvm namespace + +#endif diff --git a/lib/Target/JSBackend/MCTargetDesc/LLVMBuild.txt b/lib/Target/JSBackend/MCTargetDesc/LLVMBuild.txt new file mode 100644 index 0000000000..91127251c9 --- /dev/null +++ b/lib/Target/JSBackend/MCTargetDesc/LLVMBuild.txt @@ -0,0 +1,23 @@ +;===- ./lib/Target/JSBackend/MCTargetDesc/LLVMBuild.txt --------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = JSBackendDesc +parent = JSBackend +required_libraries = MC Support JSBackendInfo +add_to_library_groups = JSBackend diff --git a/lib/Target/JSBackend/MCTargetDesc/Makefile b/lib/Target/JSBackend/MCTargetDesc/Makefile new file mode 100644 index 0000000000..9bf7e902af --- /dev/null +++ b/lib/Target/JSBackend/MCTargetDesc/Makefile @@ -0,0 +1,16 @@ +##===- lib/Target/JSBackend/TargetDesc/Makefile ------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../../../.. +LIBRARYNAME = LLVMJSBackendDesc + +# Hack: we need to include 'main' target directory to grab private headers +CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/.. + +include $(LEVEL)/Makefile.common diff --git a/lib/Target/JSBackend/Makefile b/lib/Target/JSBackend/Makefile index 8a15e7f4c1..8d8336bdbd 100644 --- a/lib/Target/JSBackend/Makefile +++ b/lib/Target/JSBackend/Makefile @@ -9,7 +9,7 @@ LEVEL = ../../.. LIBRARYNAME = LLVMJSBackendCodeGen -DIRS = TargetInfo +DIRS = MCTargetDesc TargetInfo include $(LEVEL)/Makefile.common diff --git a/lib/Target/JSBackend/OptPasses.h b/lib/Target/JSBackend/OptPasses.h index 81e3b5ed18..2f90b568b0 100644 --- a/lib/Target/JSBackend/OptPasses.h +++ b/lib/Target/JSBackend/OptPasses.h @@ -1,4 +1,4 @@ -//===-- JSTargetMachine.h - TargetMachine for the C++ backend --*- C++ -*-===// +//===-- JSTargetMachine.h - TargetMachine for the JS Backend ---*- C++ -*-===// // // The LLVM Compiler Infrastructure // diff --git a/lib/Target/JSBackend/SimplifyAllocas.cpp b/lib/Target/JSBackend/SimplifyAllocas.cpp index 858ded32a1..a6c090e7e4 100644 --- a/lib/Target/JSBackend/SimplifyAllocas.cpp +++ b/lib/Target/JSBackend/SimplifyAllocas.cpp @@ -1,4 +1,4 @@ -//===-- SimplifyAllocas.cpp - TargetMachine for the C++ backend --*- C++ -*-===// +//===-- SimplifyAllocas.cpp - Alloca optimization ---------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -6,29 +6,23 @@ // License. See LICENSE.TXT for details. // //===-----------------------------------------------------------------------===// +// +// There shouldn't be any opportunities for this pass to do anything if the +// regular LLVM optimizer passes are run. However, it does make things nicer +// at -O0. +// +//===-----------------------------------------------------------------------===// -#include <OptPasses.h> +#include "OptPasses.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Function.h" -// XXX -#include "llvm/Support/FormattedStream.h" -#include <stdio.h> -#define dump(x) fprintf(stderr, x "\n") -#define dumpv(x, ...) fprintf(stderr, x "\n", __VA_ARGS__) -#define dumpfail(x) { fprintf(stderr, x "\n"); fprintf(stderr, "%s : %d\n", __FILE__, __LINE__); report_fatal_error("fail"); } -#define dumpfailv(x, ...) { fprintf(stderr, x "\n", __VA_ARGS__); fprintf(stderr, "%s : %d\n", __FILE__, __LINE__); report_fatal_error("fail"); } -#define dumpIR(value) { \ - std::string temp; \ - raw_string_ostream stream(temp); \ - stream << *(value); \ - fprintf(stderr, "%s\n", temp.c_str()); \ -} +#ifdef NDEBUG #undef assert -#define assert(x) { if (!(x)) dumpfail(#x); } -// XXX +#define assert(x) { if (!(x)) report_fatal_error(#x); } +#endif namespace llvm { @@ -115,4 +109,3 @@ extern FunctionPass *createSimplifyAllocasPass() { } } // End llvm namespace - diff --git a/lib/Target/JSBackend/TargetInfo/JSBackendTargetInfo.cpp b/lib/Target/JSBackend/TargetInfo/JSBackendTargetInfo.cpp index cf06eaceea..66a3f4d6e8 100644 --- a/lib/Target/JSBackend/TargetInfo/JSBackendTargetInfo.cpp +++ b/lib/Target/JSBackend/TargetInfo/JSBackendTargetInfo.cpp @@ -8,6 +8,7 @@ //===--------------------------------------------------------------------===// #include "JSTargetMachine.h" +#include "MCTargetDesc/JSBackendMCTargetDesc.h" #include "llvm/IR/Module.h" #include "llvm/Support/TargetRegistry.h" using namespace llvm; @@ -15,8 +16,21 @@ using namespace llvm; Target llvm::TheJSBackendTarget; static unsigned JSBackend_TripleMatchQuality(const std::string &TT) { - // This class always works, but shouldn't be the default in most cases. - return 1; + switch (Triple(TT).getArch()) { + case Triple::asmjs: + // That's us! + return 20; + + case Triple::le32: + case Triple::x86: + // For compatibility with older versions of Emscripten, we also basically + // support generating code for le32-unknown-nacl and i386-pc-linux-gnu, + // but we use a low number here so that we're not the default. + return 1; + + default: + return 0; + } } extern "C" void LLVMInitializeJSBackendTargetInfo() { @@ -24,5 +38,3 @@ extern "C" void LLVMInitializeJSBackendTargetInfo() { "JavaScript (asm.js, emscripten) backend", &JSBackend_TripleMatchQuality); } - -extern "C" void LLVMInitializeJSBackendTargetMC() {} |