Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Import of fastcomp commit 4105790f1549808c1f1daa5250b4ada5f41a5c02 #52

Merged
merged 1 commit into from
Sep 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ set(LLVM_ALL_TARGETS
ARM
BPF
Hexagon
JSBackend # @LOCALMOD
Mips
MSP430
NVPTX
Expand Down
9 changes: 9 additions & 0 deletions include/llvm/ADT/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Triple {
nvptx64, // NVPTX: 64-bit
le32, // le32: generic little-endian 32-bit CPU (PNaCl)
le64, // le64: generic little-endian 64-bit CPU (PNaCl)
asmjs, // asm.js JavaScript subset @LOCALMOD Emscripten
amdil, // AMDIL
amdil64, // AMDIL with 64-bit pointers
hsail, // AMD HSAIL
Expand Down Expand Up @@ -156,6 +157,7 @@ class Triple {
Haiku,
Minix,
RTEMS,
Emscripten, // Emscripten JavaScript runtime @LOCALMOD Emscripten
NaCl, // Native Client
CNK, // BG/P Compute-Node Kernel
Bitrig,
Expand Down Expand Up @@ -531,6 +533,13 @@ class Triple {
return getOS() == Triple::NaCl;
}

// @LOCALMOD-START Emscripten
/// Tests whether the OS is Emscripten.
bool isOSEmscripten() const {
return getOS() == Triple::Emscripten;
}
// @LOCALMOD-END Emscripten

/// Tests whether the OS is Linux.
bool isOSLinux() const {
return getOS() == Triple::Linux;
Expand Down
13 changes: 13 additions & 0 deletions lib/Support/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const char *Triple::getArchTypeName(ArchType Kind) {
case nvptx64: return "nvptx64";
case le32: return "le32";
case le64: return "le64";
case asmjs: return "asmjs"; // @LOCALMOD Emscripten
case amdil: return "amdil";
case amdil64: return "amdil64";
case hsail: return "hsail";
Expand Down Expand Up @@ -121,6 +122,8 @@ const char *Triple::getArchTypePrefix(ArchType Kind) {
case le32: return "le32";
case le64: return "le64";

case asmjs: return "asmjs"; // @LOCALMOD Emscripten

case amdil:
case amdil64: return "amdil";

Expand Down Expand Up @@ -180,6 +183,7 @@ const char *Triple::getOSTypeName(OSType Kind) {
case Haiku: return "haiku";
case Minix: return "minix";
case RTEMS: return "rtems";
case Emscripten: return "emscripten"; // @LOCALMOD Emscripten
case NaCl: return "nacl";
case CNK: return "cnk";
case Bitrig: return "bitrig";
Expand Down Expand Up @@ -273,6 +277,7 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
.Case("nvptx64", nvptx64)
.Case("le32", le32)
.Case("le64", le64)
.Case("asmjs", asmjs) // @LOCALMOD Emscripten
.Case("amdil", amdil)
.Case("amdil64", amdil64)
.Case("hsail", hsail)
Expand Down Expand Up @@ -384,6 +389,7 @@ static Triple::ArchType parseArch(StringRef ArchName) {
.Case("nvptx64", Triple::nvptx64)
.Case("le32", Triple::le32)
.Case("le64", Triple::le64)
.Case("asmjs", Triple::asmjs) // @LOCALMOD Emscripten
.Case("amdil", Triple::amdil)
.Case("amdil64", Triple::amdil64)
.Case("hsail", Triple::hsail)
Expand Down Expand Up @@ -450,6 +456,7 @@ static Triple::OSType parseOS(StringRef OSName) {
.StartsWith("haiku", Triple::Haiku)
.StartsWith("minix", Triple::Minix)
.StartsWith("rtems", Triple::RTEMS)
.StartsWith("emscripten", Triple::Emscripten) // @LOCALMOD Emscripten
.StartsWith("nacl", Triple::NaCl)
.StartsWith("cnk", Triple::CNK)
.StartsWith("bitrig", Triple::Bitrig)
Expand Down Expand Up @@ -584,6 +591,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
case Triple::amdil:
case Triple::amdil64:
case Triple::armeb:
case Triple::asmjs: // @LOCALMOD Emscripten
case Triple::avr:
case Triple::bpfeb:
case Triple::bpfel:
Expand Down Expand Up @@ -1127,6 +1135,7 @@ static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
case llvm::Triple::armeb:
case llvm::Triple::hexagon:
case llvm::Triple::le32:
case llvm::Triple::asmjs: // @LOCALMOD Emscripten
case llvm::Triple::mips:
case llvm::Triple::mipsel:
case llvm::Triple::nvptx:
Expand Down Expand Up @@ -1207,6 +1216,7 @@ Triple Triple::get32BitArchVariant() const {
case Triple::hexagon:
case Triple::kalimba:
case Triple::le32:
case Triple::asmjs: // @LOCALMOD Emscripten
case Triple::mips:
case Triple::mipsel:
case Triple::nvptx:
Expand Down Expand Up @@ -1256,6 +1266,7 @@ Triple Triple::get64BitArchVariant() const {
case Triple::r600:
case Triple::tce:
case Triple::xcore:
case Triple::asmjs: // @LOCALMOD Emscripten
case Triple::sparcel:
case Triple::shave:
T.setArch(UnknownArch);
Expand Down Expand Up @@ -1313,6 +1324,7 @@ Triple Triple::getBigEndianArchVariant() const {
case Triple::amdgcn:
case Triple::amdil64:
case Triple::amdil:
case Triple::asmjs:
case Triple::avr:
case Triple::hexagon:
case Triple::hsail64:
Expand Down Expand Up @@ -1393,6 +1405,7 @@ bool Triple::isLittleEndian() const {
case Triple::amdil64:
case Triple::amdil:
case Triple::arm:
case Triple::asmjs:
case Triple::avr:
case Triple::bpfel:
case Triple::hexagon:
Expand Down
10 changes: 10 additions & 0 deletions lib/Target/JSBackend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_llvm_target(JSBackendCodeGen
JSBackend.cpp
JSTargetMachine.cpp
JSTargetTransformInfo.cpp
)

add_dependencies(LLVMJSBackendCodeGen intrinsics_gen)

add_subdirectory(TargetInfo)
add_subdirectory(MCTargetDesc)
24 changes: 24 additions & 0 deletions lib/Target/JSBackend/JS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===-- JS.h - Top-level interface for JS representation ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the entry points for global functions defined in the JS
// target library, as used by the LLVM JIT.
//
//===----------------------------------------------------------------------===//

#ifndef TARGET_JS_H
#define TARGET_JS_H

namespace llvm {

class JSTargetMachine;

} // End llvm namespace

#endif
40 changes: 40 additions & 0 deletions lib/Target/JSBackend/JSBackend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===-- JSBackend.cpp - Library for converting LLVM code to JS -----===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements compiling of LLVM IR, which is assumed to have been
// simplified using the PNaCl passes, i64 legalization, and other necessary
// transformations, into JavaScript in asm.js format, suitable for passing
// to emscripten for final processing.
//
//===----------------------------------------------------------------------===//

#include "JSTargetMachine.h"
#include "MCTargetDesc/JSBackendMCTargetDesc.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include "llvm/Target/TargetLowering.h"

using namespace llvm;

extern "C" void LLVMInitializeJSBackendTarget() {
// Register the target.
RegisterTargetMachine<JSTargetMachine> X(TheJSBackendTarget);
}

//===----------------------------------------------------------------------===//
// External Interface declaration
//===----------------------------------------------------------------------===//

bool JSTargetMachine::addPassesToEmitFile(
PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
bool DisableVerify, AnalysisID StartBefore,
AnalysisID StartAfter, AnalysisID StopAfter,
MachineFunctionInitializer *MFInitializer) {
return false;
}
48 changes: 48 additions & 0 deletions lib/Target/JSBackend/JSTargetMachine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===-- JSTargetMachine.cpp - Define TargetMachine for the JS -------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the JS specific subclass of TargetMachine.
//
//===----------------------------------------------------------------------===//

#include "JSTargetMachine.h"
#include "JSTargetTransformInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Support/TargetRegistry.h"
using namespace llvm;

extern const llvm::SubtargetFeatureKV JSSubTypeKV[] = {
{ "asmjs", "Select the asmjs processor", { }, { } }
};

static const llvm::SubtargetInfoKV JSProcSchedModels[] = {
{ "asmjs", &MCSchedModel::GetDefaultSchedModel() }
};

JSSubtarget::JSSubtarget(const TargetMachine& TM, const Triple &TT) :
TargetSubtargetInfo(TT, "asmjs", "asmjs", None, makeArrayRef(JSSubTypeKV, 1), JSProcSchedModels, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr),
TL(TM)
{}


JSTargetMachine::JSTargetMachine(const Target &T, const Triple &TT,
StringRef CPU, StringRef FS, const TargetOptions &Options,
Optional<Reloc::Model>& RM, CodeModel::Model CM,
CodeGenOpt::Level OL)
: LLVMTargetMachine(T, "e-p:32:32-i64:64-v128:32:128-n32-S128", TT,
CPU, FS, Options, Reloc::Static, CM, OL),
ST(*this, TT) {
}

TargetIRAnalysis JSTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(JSTTIImpl(this, F));
});
}

71 changes: 71 additions & 0 deletions lib/Target/JSBackend/JSTargetMachine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//===-- JSTargetMachine.h - TargetMachine for the JS Backend ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===---------------------------------------------------------------------===//
//
// This file declares the TargetMachine that is used by the JS/asm.js/
// emscripten backend.
//
//===---------------------------------------------------------------------===//

#ifndef JSTARGETMACHINE_H
#define JSTARGETMACHINE_H

#include "JS.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include "llvm/Target/TargetLowering.h"

namespace llvm {

class formatted_raw_ostream;

class JSTargetLowering : public TargetLowering {
public:
explicit JSTargetLowering(const TargetMachine& TM) : TargetLowering(TM) {}
};

class JSSubtarget : public TargetSubtargetInfo {
JSTargetLowering TL;

public:
JSSubtarget(const TargetMachine& TM, const Triple &TT);

const TargetLowering *getTargetLowering() const override {
return &TL;
}
};

class JSTargetMachine : public LLVMTargetMachine {
const JSSubtarget ST;

public:
JSTargetMachine(const Target &T, const Triple &TT,
StringRef CPU, StringRef FS, const TargetOptions &Options,
Optional<Reloc::Model>& RM, CodeModel::Model CM,
CodeGenOpt::Level OL);

bool addPassesToEmitFile(
PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
bool DisableVerify = true, AnalysisID StartBefore = nullptr,
AnalysisID StartAfter = nullptr, AnalysisID StopAfter = nullptr,
MachineFunctionInitializer *MFInitializer = nullptr) override;

TargetIRAnalysis getTargetIRAnalysis() override;

const TargetSubtargetInfo *getJSSubtargetImpl() const {
return &ST;
}

const JSSubtarget *getSubtargetImpl(const Function &F) const override {
return &ST;
}
};

} // End llvm namespace

#endif
Loading