This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
forked from luqmana/llvm
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a minimal import of the emscripten "fastcomp" LLVM patchset. All it contains is the target definitions necessary to create a TargetMachine with the correct data layout. With this rustc can emit LLVM IR that emcc will run through the PNaCl lagalizer and the JS backend to generate asm.js.
- Loading branch information
Showing
21 changed files
with
599 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,6 +224,7 @@ set(LLVM_ALL_TARGETS | |
ARM | ||
BPF | ||
Hexagon | ||
JSBackend # @LOCALMOD | ||
Mips | ||
MSP430 | ||
NVPTX | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.