Changeset 182483 in webkit for trunk/Source/JavaScriptCore/llvm


Ignore:
Timestamp:
Apr 7, 2015, 12:41:12 PM (10 years ago)
Author:
[email protected]
Message:

Make it possible to enable LLVM FastISel
https://bugs.webkit.org/show_bug.cgi?id=143489

Reviewed by Michael Saboff.

The decision to enable FastISel is made by Options.h|cpp, but the LLVM library can disable it if it finds that it is built
against a version of LLVM that doesn't support it. Thereafter, JSC::enableLLVMFastISel is the flag that tells the system
if we should enable it.

  • ftl/FTLCompile.cpp:

(JSC::FTL::mmAllocateDataSection):

  • llvm/InitializeLLVM.cpp:

(JSC::initializeLLVMImpl):

  • llvm/InitializeLLVM.h:
  • llvm/InitializeLLVMLinux.cpp:

(JSC::getLLVMInitializerFunction):
(JSC::initializeLLVMImpl): Deleted.

  • llvm/InitializeLLVMMac.cpp:

(JSC::getLLVMInitializerFunction):
(JSC::initializeLLVMImpl): Deleted.

  • llvm/InitializeLLVMPOSIX.cpp:

(JSC::getLLVMInitializerFunctionPOSIX):
(JSC::initializeLLVMPOSIX): Deleted.

  • llvm/InitializeLLVMPOSIX.h:
  • llvm/InitializeLLVMWin.cpp:

(JSC::getLLVMInitializerFunction):
(JSC::initializeLLVMImpl): Deleted.

  • llvm/LLVMAPI.cpp:
  • llvm/LLVMAPI.h:
  • llvm/library/LLVMExports.cpp:

(initCommandLine):
(initializeAndGetJSCLLVMAPI):

  • runtime/Options.cpp:

(JSC::Options::initialize):

Location:
trunk/Source/JavaScriptCore/llvm
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/llvm/InitializeLLVM.cpp

    r166948 r182483  
    11/*
    2  * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030
    3131#include "LLVMAPI.h"
     32#include "Options.h"
    3233#include <pthread.h>
     34#include <wtf/DataLog.h>
    3335
    3436namespace JSC {
    3537
    3638static pthread_once_t initializeLLVMOnceKey = PTHREAD_ONCE_INIT;
     39
     40static void initializeLLVMImpl()
     41{
     42    const bool verbose =
     43        Options::verboseFTLCompilation()
     44        || Options::showFTLDisassembly()
     45        || Options::verboseFTLFailure()
     46        || Options::verboseCompilation()
     47        || Options::showDFGDisassembly()
     48        || Options::showDisassembly();
     49   
     50    LLVMInitializerFunction initializer = getLLVMInitializerFunction(verbose);
     51    if (!initializer)
     52        return;
     53   
     54    bool enableFastISel = Options::enableLLVMFastISel();
     55    llvm = initializer(WTFLogAlwaysAndCrash, &enableFastISel);
     56    if (!llvm) {
     57        if (verbose)
     58            dataLog("LLVM initilization failed.\n");
     59    }
     60    if (Options::enableLLVMFastISel() && !enableFastISel) {
     61        if (verbose)
     62            dataLog("Fast ISel requested but LLVM not new enough.\n");
     63    }
     64   
     65    enableLLVMFastISel = enableFastISel;
     66}
    3767
    3868bool initializeLLVM()
  • trunk/Source/JavaScriptCore/llvm/InitializeLLVM.h

    r171391 r182483  
    11/*
    2  * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929#if HAVE(LLVM)
    3030
     31#include "LLVMAPI.h"
    3132#include <string>
    3233#include <wtf/text/CString.h>
     
    3435namespace JSC {
    3536
    36 void initializeLLVMImpl();
     37typedef void (*LoggerFunction)(const char*, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
     38typedef LLVMAPI* (*LLVMInitializerFunction)(LoggerFunction, bool* enableFastISel);
     39
     40LLVMInitializerFunction getLLVMInitializerFunction(bool verbose);
    3741
    3842extern const CString* llvmBitcodeLibraryForInliningPath;
    3943
    40 // You msut call this before using JSC::llvm. It's safe to call this multiple times.
     44// You must call this before using JSC::llvm. It's safe to call this multiple times.
    4145// Returns true if we successfully loaded LLVM. Returns false if we didn't.
    4246bool initializeLLVM();
  • trunk/Source/JavaScriptCore/llvm/InitializeLLVMLinux.cpp

    r161498 r182483  
    22 * Copyright (C) 2013 University of Szeged. All rights reserved.
    33 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
     4 * Copyright (C) 2015 Apple Inc. All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    3435namespace JSC {
    3536
    36 void initializeLLVMImpl()
     37LLVMInitializerFunction getLLVMInitializerFunction(bool verbose)
    3738{
    38     initializeLLVMPOSIX("libllvmForJSC.so");
     39    return getLLVMInitializerFunctionPOSIX("libllvmForJSC.so", verbose);
    3940}
    4041
  • trunk/Source/JavaScriptCore/llvm/InitializeLLVMMac.cpp

    r171391 r182483  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3838namespace JSC {
    3939
    40 void initializeLLVMImpl()
     40LLVMInitializerFunction getLLVMInitializerFunction(bool verbose)
    4141{
    42     initializeLLVMPOSIX(toCString(bundlePath().data(), "/Libraries/libllvmForJSC.dylib").data());
     42    return getLLVMInitializerFunctionPOSIX(toCString(bundlePath().data(), "/Libraries/libllvmForJSC.dylib").data(), verbose);
    4343}
    4444
  • trunk/Source/JavaScriptCore/llvm/InitializeLLVMPOSIX.cpp

    r180622 r182483  
    11/*
    2  * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3636namespace JSC {
    3737
    38 typedef void (*LoggerFunction)(const char*, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
    39 typedef LLVMAPI* (*InitializerFunction)(LoggerFunction);
    40 
    41 void initializeLLVMPOSIX(const char* libraryName)
     38LLVMInitializerFunction getLLVMInitializerFunctionPOSIX(const char* libraryName, bool verbose)
    4239{
    43     const bool verbose =
    44         Options::verboseFTLCompilation()
    45         || Options::showFTLDisassembly()
    46         || Options::verboseFTLFailure()
    47         || Options::verboseCompilation()
    48         || Options::showDFGDisassembly()
    49         || Options::showDisassembly();
    50    
    5140    int flags = RTLD_NOW;
    5241   
     
    6453        if (verbose)
    6554            dataLog("Failed to load LLVM library at ", libraryName, ": ", dlerror(), "\n");
    66         return;
     55        return nullptr;
    6756    }
    6857   
    6958    const char* symbolName = "initializeAndGetJSCLLVMAPI";
    70     InitializerFunction initializer = bitwise_cast<InitializerFunction>(
     59    LLVMInitializerFunction initializer = bitwise_cast<LLVMInitializerFunction>(
    7160        dlsym(library, symbolName));
    7261    if (!initializer) {
    7362        if (verbose)
    7463            dataLog("Failed to find ", symbolName, " in ", libraryName, ": ", dlerror());
    75         return;
     64        return nullptr;
    7665    }
    7766   
    78     llvm = initializer(WTFLogAlwaysAndCrash);
    79     if (!llvm) {
    80         if (verbose)
    81             dataLog("LLVM initilization failed.\n");
    82     }
     67    return initializer;
    8368}
    8469
  • trunk/Source/JavaScriptCore/llvm/InitializeLLVMPOSIX.h

    r164424 r182483  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929#if HAVE(LLVM)
    3030
     31#include "InitializeLLVM.h"
     32
    3133namespace JSC {
    3234
    33 void initializeLLVMPOSIX(const char* libraryName);
     35LLVMInitializerFunction getLLVMInitializerFunctionPOSIX(const char* libraryName, bool verbose);
    3436
    3537} // namespace JSC
  • trunk/Source/JavaScriptCore/llvm/InitializeLLVMWin.cpp

    r170130 r182483  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3434namespace JSC {
    3535
    36 typedef LLVMAPI* (*InitializerFunction)(void(*)(const char*, ...));
    37 
    38 void initializeLLVMImpl()
     36LLVMInitializerFunction getLLVMInitializerFunction(bool /* verbose */)
    3937{
    4038    const wchar_t* libraryName = L"libllvmForJSC.dll";
     
    4341
    4442    if (!library)
    45         return;
     43        return nullptr;
    4644
    4745    const char* symbolName = "initializeAndGetJSCLLVMAPI";
    48     InitializerFunction initializer = bitwise_cast<InitializerFunction>(GetProcAddress(library, symbolName));
    49     if (initializer)
    50         llvm = initializer(WTFLogAlwaysAndCrash);
     46    return bitwise_cast<LLVMInitializerFunction>(GetProcAddress(library, symbolName));
    5147}
    5248
  • trunk/Source/JavaScriptCore/llvm/LLVMAPI.cpp

    r157260 r182483  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3232
    3333LLVMAPI* llvm;
     34bool enableLLVMFastISel;
    3435
    3536}
  • trunk/Source/JavaScriptCore/llvm/LLVMAPI.h

    r164424 r182483  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3939    FOR_EACH_LLVM_API_FUNCTION(LLVM_API_FUNCTION_DECLARATION)
    4040#undef LLVM_API_FUNCTION_DECLARATION
     41   
     42    // Functions that we add conditionally.
     43    void (*AddLowerSwitchPass)(LLVMPassManagerRef PM);
    4144};
    4245
    4346extern LLVMAPI* llvm;
     47extern bool enableLLVMFastISel;
    4448
    4549} // namespace JSC
  • trunk/Source/JavaScriptCore/llvm/library/LLVMExports.cpp

    r181083 r182483  
    5555
    5656static void llvmCrash(const char*) NO_RETURN;
    57 extern "C" WTF_EXPORT_PRIVATE JSC::LLVMAPI* initializeAndGetJSCLLVMAPI(void (*)(const char*, ...) NO_RETURN);
     57extern "C" WTF_EXPORT_PRIVATE JSC::LLVMAPI* initializeAndGetJSCLLVMAPI(
     58    void (*)(const char*, ...) NO_RETURN, bool* enableFastISel);
    5859
    5960static void llvmCrash(const char* reason)
     
    6263}
    6364
    64 extern "C" JSC::LLVMAPI* initializeAndGetJSCLLVMAPI(void (*callback)(const char*, ...) NO_RETURN)
     65template<typename... Args>
     66void initCommandLine(Args... args)
     67{
     68    const char* theArgs[] = { args... };
     69    llvm::cl::ParseCommandLineOptions(sizeof(theArgs) / sizeof(const char*), theArgs);
     70}
     71
     72extern "C" JSC::LLVMAPI* initializeAndGetJSCLLVMAPI(
     73    void (*callback)(const char*, ...) NO_RETURN,
     74    bool* enableFastISel)
    6575{
    6676    g_llvmTrapCallback = callback;
     
    100110#endif
    101111   
    102     const char* args[] = {
    103         "llvmForJSC.dylib",
    104         "-enable-patchpoint-liveness=true"
    105     };
    106     llvm::cl::ParseCommandLineOptions(sizeof(args) / sizeof(const char*), args);
     112#if LLVM_VERSION_MAJOR >= 4 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6)
     113    // It's OK to have fast ISel, if it was requested.
     114#else
     115    // We don't have enough support for fast ISel. Disable it.
     116    *enableFastISel = false;
     117#endif
     118
     119    if (*enableFastISel)
     120        initCommandLine("llvmForJSC.dylib", "-enable-misched=false", "-regalloc=basic");
     121    else
     122        initCommandLine("llvmForJSC.dylib", "-enable-patchpoint-liveness=true");
    107123   
    108124    JSC::LLVMAPI* result = new JSC::LLVMAPI;
     125   
     126    // Initialize the whole thing to null.
     127    memset(result, 0, sizeof(*result));
    109128   
    110129#define LLVM_API_FUNCTION_ASSIGNMENT(returnType, name, signature) \
     
    112131    FOR_EACH_LLVM_API_FUNCTION(LLVM_API_FUNCTION_ASSIGNMENT);
    113132#undef LLVM_API_FUNCTION_ASSIGNMENT
     133   
     134    // Handle conditionally available functions.
     135#if LLVM_VERSION_MAJOR >= 4 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6)
     136    result->AddLowerSwitchPass = LLVMAddLowerSwitchPass;
     137#endif
    114138   
    115139    return result;
Note: See TracChangeset for help on using the changeset viewer.