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

Commit

Permalink
Merge pull request #50 from brson/fastcomp-squash
Browse files Browse the repository at this point in the history
Squash of fastcomp commit 4105790
  • Loading branch information
alexcrichton authored Sep 7, 2016
2 parents 16b79d0 + 8d07d6d commit c3bfb2c
Show file tree
Hide file tree
Showing 214 changed files with 35,635 additions and 9 deletions.
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
2 changes: 2 additions & 0 deletions emscripten-version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"1.36.9"

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
74 changes: 74 additions & 0 deletions include/llvm/Analysis/NaCl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//===-- NaCl.h - NaCl Analysis ---------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_ANALYSIS_NACL_H
#define LLVM_ANALYSIS_NACL_H

#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <string>

namespace llvm {

class FunctionPass;
class ModulePass;
extern cl::opt<bool> PNaClABIAllowDebugMetadata;

class PNaClABIErrorReporter {
PNaClABIErrorReporter(const PNaClABIErrorReporter&) = delete;
void operator=(const PNaClABIErrorReporter&) = delete;
public:
PNaClABIErrorReporter() : ErrorCount(0), Errors(ErrorString),
UseFatalErrors(true) {}
~PNaClABIErrorReporter() {}
// Return the number of verification errors from the last run.
int getErrorCount() const { return ErrorCount; }
// Print the error messages to O
void printErrors(llvm::raw_ostream &O) {
Errors.flush();
O << ErrorString;
}
// Increments the error count and returns an ostream to which the error
// message can be streamed.
raw_ostream &addError() {
ErrorCount++;
return Errors;
}
// Reset the error count and error messages.
void reset() {
ErrorCount = 0;
Errors.flush();
ErrorString.clear();
}
void setNonFatal() {
UseFatalErrors = false;
}
void checkForFatalErrors() {
if (UseFatalErrors && ErrorCount != 0) {
printErrors(errs());
report_fatal_error("PNaCl ABI verification failed");
}
}
private:
int ErrorCount;
std::string ErrorString;
raw_string_ostream Errors;
bool UseFatalErrors;
};

FunctionPass *createPNaClABIVerifyFunctionsPass(
PNaClABIErrorReporter *Reporter);
ModulePass *createPNaClABIVerifyModulePass(PNaClABIErrorReporter *Reporter,
bool StreamingMode = false);

}


#endif
50 changes: 50 additions & 0 deletions include/llvm/IR/Intrinsics.td
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,56 @@ def int_convertuu : Intrinsic<[llvm_anyint_ty],
def int_clear_cache : Intrinsic<[], [llvm_ptr_ty, llvm_ptr_ty],
[], "llvm.clear_cache">;

// @LOCALMOD-BEGIN
//===----------------------- Native Client Intrinsics ---------------------===//
// NaCl-specific setjmp/longjmp intrinsics.
// See https://code.google.com/p/nativeclient/issues/detail?id=3429
def int_nacl_setjmp : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty]>;
def int_nacl_longjmp : Intrinsic<[], [llvm_ptr_ty, llvm_i32_ty],
[IntrNoReturn]>;

// Fast built-in version of NaCl's tls_get() IRT interface.
def int_nacl_read_tp : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>;

// Atomic intrinsics.
//
// Volatiles and atomics are encoded through these intrinsics to make
// them platform-independent, remove some of LLVM's legacy, and isolate
// PNaCl from future changes to IR. The intrinsics allow user code to
// use `__sync_*` builtins as well as C11/C++11 atomics.
//
// These are further documented in docs/PNaClLangRef.rst.
//
// Note that IntrReadWriteArgMem is used in all cases to prevent
// reordering.
def int_nacl_atomic_load : Intrinsic<[llvm_anyint_ty],
[LLVMPointerType<LLVMMatchType<0>>, llvm_i32_ty],
[IntrArgMemOnly]>;
def int_nacl_atomic_store : Intrinsic<[],
[llvm_anyint_ty, LLVMPointerType<LLVMMatchType<0>>, llvm_i32_ty],
[IntrArgMemOnly]>;
def int_nacl_atomic_rmw : Intrinsic<[llvm_anyint_ty],
[llvm_i32_ty, LLVMPointerType<LLVMMatchType<0>>, LLVMMatchType<0>,
llvm_i32_ty],
[IntrArgMemOnly]>;
def int_nacl_atomic_cmpxchg : Intrinsic<[llvm_anyint_ty],
[LLVMPointerType<LLVMMatchType<0>>, LLVMMatchType<0>, LLVMMatchType<0>,
llvm_i32_ty, llvm_i32_ty],
[IntrArgMemOnly]>;
def int_nacl_atomic_fence : Intrinsic<[], [llvm_i32_ty],
[IntrArgMemOnly]>;
def int_nacl_atomic_fence_all : Intrinsic<[], [],
[IntrArgMemOnly]>;
def int_nacl_atomic_is_lock_free : Intrinsic<[llvm_i1_ty],
[llvm_i32_ty, llvm_ptr_ty], [IntrNoMem]>,
GCCBuiltin<"__nacl_atomic_is_lock_free">;
// @LOCALMOD-END
// Calculate the Absolute Differences of the two input vectors.
def int_sabsdiff : Intrinsic<[llvm_anyvector_ty],
[ LLVMMatchType<0>, LLVMMatchType<0> ], [IntrNoMem]>;
def int_uabsdiff : Intrinsic<[llvm_anyvector_ty],
[ LLVMMatchType<0>, LLVMMatchType<0> ], [IntrNoMem]>;

//===-------------------------- Masked Intrinsics -------------------------===//
//
def int_masked_store : Intrinsic<[], [llvm_anyvector_ty,
Expand Down
110 changes: 110 additions & 0 deletions include/llvm/IR/NaClAtomicIntrinsics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//===-- llvm/IR/NaClAtomicIntrinsics.h - NaCl Atomic Intrinsics -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file describes atomic intrinsic functions that are specific to NaCl.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_IR_NACL_ATOMIC_INTRINSICS_H
#define LLVM_IR_NACL_ATOMIC_INTRINSICS_H

#include "llvm/IR/Intrinsics.h"
#include "llvm/Support/Compiler.h"
#include <cstddef>

namespace llvm {

namespace NaCl {

static const size_t NumAtomicIntrinsics = 6;
static const size_t NumAtomicIntrinsicOverloadTypes = 4;
static const size_t MaxAtomicIntrinsicsParameters = 5;

/// Describe all the atomic intrinsics and their type signature. Most
/// can be overloaded on a type.
class AtomicIntrinsics {
public:
enum ParamType {
NoP, /// No parameter.
Int, /// Overloaded.
Ptr, /// Overloaded.
RMW, /// Atomic RMW operation type.
Mem /// Memory order.
};

struct AtomicIntrinsic {
Type *OverloadedType;
Intrinsic::ID ID;
uint8_t Overloaded : 1;
uint8_t NumParams : 7;
uint8_t ParamType[MaxAtomicIntrinsicsParameters];

Function *getDeclaration(Module *M) const {
// The atomic intrinsic can be overloaded on zero or one type,
// which is needed to create the function's declaration.
return Intrinsic::getDeclaration(
M, ID, ArrayRef<Type *>(&OverloadedType, Overloaded ? 1 : 0));
}
};

AtomicIntrinsics(LLVMContext &C);
~AtomicIntrinsics() {}

typedef ArrayRef<AtomicIntrinsic> View;

/// Access all atomic intrinsics, which can then be iterated over.
View allIntrinsicsAndOverloads() const;
/// Access a particular atomic intrinsic.
/// \returns 0 if no intrinsic was found.
const AtomicIntrinsic *find(Intrinsic::ID ID, Type *OverloadedType) const;

private:
AtomicIntrinsic I[NumAtomicIntrinsics][NumAtomicIntrinsicOverloadTypes];

AtomicIntrinsics() = delete;
AtomicIntrinsics(const AtomicIntrinsics &) = delete;
AtomicIntrinsics &operator=(const AtomicIntrinsics &) = delete;
};

/// Operations that can be represented by the @llvm.nacl.atomic.rmw
/// intrinsic.
///
/// Do not reorder these values: their order offers forward
/// compatibility of bitcode targeted to NaCl.
enum AtomicRMWOperation {
AtomicInvalid = 0, // Invalid, keep first.
AtomicAdd,
AtomicSub,
AtomicOr,
AtomicAnd,
AtomicXor,
AtomicExchange,
AtomicNum // Invalid, keep last.
};

/// Memory orderings supported by C11/C++11.
///
/// Do not reorder these values: their order offers forward
/// compatibility of bitcode targeted to NaCl.
enum MemoryOrder {
MemoryOrderInvalid = 0, // Invalid, keep first.
MemoryOrderRelaxed,
MemoryOrderConsume,
MemoryOrderAcquire,
MemoryOrderRelease,
MemoryOrderAcquireRelease,
MemoryOrderSequentiallyConsistent,
MemoryOrderNum // Invalid, keep last.
};

} // End NaCl namespace

} // End llvm namespace

#endif
63 changes: 63 additions & 0 deletions include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,69 @@ void initializeVirtRegMapPass(PassRegistry&);
void initializeVirtRegRewriterPass(PassRegistry&);
void initializeWholeProgramDevirtPass(PassRegistry &);
void initializeWinEHPreparePass(PassRegistry&);

// @LOCALMOD-BEGIN
void initializeAddPNaClExternalDeclsPass(PassRegistry&);
void initializeAllocateDataSegmentPass(PassRegistry&);
void initializeBackendCanonicalizePass(PassRegistry&);
void initializeCanonicalizeMemIntrinsicsPass(PassRegistry&);
void initializeCleanupUsedGlobalsMetadataPass(PassRegistry&);
void initializeConstantInsertExtractElementIndexPass(PassRegistry&);
void initializeExpandAllocasPass(PassRegistry&);
void initializeExpandArithWithOverflowPass(PassRegistry&);
void initializeExpandByValPass(PassRegistry&);
void initializeExpandConstantExprPass(PassRegistry&);
void initializeExpandCtorsPass(PassRegistry&);
void initializeExpandGetElementPtrPass(PassRegistry&);
void initializeExpandIndirectBrPass(PassRegistry&);
void initializeExpandLargeIntegersPass(PassRegistry&);
void initializeExpandShuffleVectorPass(PassRegistry&);
void initializeExpandSmallArgumentsPass(PassRegistry&);
void initializeExpandStructRegsPass(PassRegistry&);
void initializeExpandTlsConstantExprPass(PassRegistry&);
void initializeExpandTlsPass(PassRegistry&);
void initializeExpandVarArgsPass(PassRegistry&);
void initializeFixVectorLoadStoreAlignmentPass(PassRegistry&);
void initializeFlattenGlobalsPass(PassRegistry&);
void initializeGlobalCleanupPass(PassRegistry&);
void initializeGlobalizeConstantVectorsPass(PassRegistry&);
void initializeInsertDivideCheckPass(PassRegistry&);
void initializeInternalizeUsedGlobalsPass(PassRegistry&);
void initializeNaClCcRewritePass(PassRegistry&);
void initializeNormalizeAlignmentPass(PassRegistry&);
void initializePNaClABIVerifyFunctionsPass(PassRegistry&);
void initializePNaClABIVerifyModulePass(PassRegistry&);
void initializePNaClSjLjEHPass(PassRegistry&);
void initializePromoteI1OpsPass(PassRegistry&);
void initializePromoteIntegersPass(PassRegistry&);
void initializeRemoveAsmMemoryPass(PassRegistry&);
void initializeRenameEntryPointPass(PassRegistry&);
void initializeReplacePtrsWithIntsPass(PassRegistry&);
void initializeResolveAliasesPass(PassRegistry&);
void initializeResolvePNaClIntrinsicsPass(PassRegistry&);
void initializeRewriteAtomicsPass(PassRegistry&);
void initializeRewriteLLVMIntrinsicsPass(PassRegistry&);
void initializeRewritePNaClLibraryCallsPass(PassRegistry&);
void initializeSandboxIndirectCallsPass(PassRegistry&);
void initializeSandboxMemoryAccessesPass(PassRegistry&);
void initializeSimplifyAllocasPass(PassRegistry&);
void initializeSimplifyStructRegSignaturesPass(PassRegistry&);
void initializeStripAttributesPass(PassRegistry&);
void initializeStripMetadataPass(PassRegistry&);
void initializeStripModuleFlagsPass(PassRegistry&);
void initializeStripDanglingDISubprogramsPass(PassRegistry&);
void initializeStripTlsPass(PassRegistry&);
void initializeSubstituteUndefsPass(PassRegistry&);
// Emscripten passes:
void initializeExpandI64Pass(PassRegistry&);
void initializeExpandInsertExtractElementPass(PassRegistry&);
void initializeLowerEmAsyncifyPass(PassRegistry&);
void initializeLowerEmExceptionsPass(PassRegistry&);
void initializeLowerEmSetjmpPass(PassRegistry&);
void initializeNoExitRuntimePass(PassRegistry&);
// Emscripten passes end.
// @LOCALMOD-END

void initializeWriteBitcodePassPass(PassRegistry &);
void initializeXRayInstrumentationPass(PassRegistry &);
}
Expand Down
Loading

0 comments on commit c3bfb2c

Please sign in to comment.