From bd7b1c89fccd48bf967881a49d97e6645d4b3338 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 13 Jun 2015 19:50:29 +0000 Subject: [PATCH] [ExecutionEngine] ArrayRefize argument passing. No functionality change intended. llvm-svn: 239687 --- .../include/llvm/ExecutionEngine/ExecutionEngine.h | 2 +- llvm/lib/ExecutionEngine/ExecutionEngine.cpp | 2 +- llvm/lib/ExecutionEngine/Interpreter/Execution.cpp | 3 +- .../Interpreter/ExternalFunctions.cpp | 49 ++++++++-------------- .../ExecutionEngine/Interpreter/Interpreter.cpp | 14 +++---- llvm/lib/ExecutionEngine/Interpreter/Interpreter.h | 6 +-- llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp | 3 +- llvm/lib/ExecutionEngine/MCJIT/MCJIT.h | 2 +- .../ExecutionEngine/Orc/OrcMCJITReplacement.cpp | 2 +- llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h | 2 +- 10 files changed, 34 insertions(+), 51 deletions(-) diff --git a/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h b/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h index 4b2add8..f99c4f5 100644 --- a/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h +++ b/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h @@ -205,7 +205,7 @@ public: /// runFunction - Execute the specified function with the specified arguments, /// and return the result. virtual GenericValue runFunction(Function *F, - const std::vector &ArgValues) = 0; + ArrayRef ArgValues) = 0; /// getPointerToNamedFunction - This method returns the address of the /// specified function by using the dlsym function call. As such it is only diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp index 9e71b10..b0d4190 100644 --- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp @@ -376,7 +376,7 @@ void ExecutionEngine::runStaticConstructorsDestructors(Module &module, // Execute the ctor/dtor function! if (Function *F = dyn_cast(FP)) - runFunction(F, std::vector()); + runFunction(F, None); // FIXME: It is marginally lame that we just do nothing here if we see an // entry we don't recognize. It might not be unreasonable for the verifier diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp index 39a8027..dbfa37e 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -2073,8 +2073,7 @@ GenericValue Interpreter::getOperandValue(Value *V, ExecutionContext &SF) { //===----------------------------------------------------------------------===// // callFunction - Execute the specified function... // -void Interpreter::callFunction(Function *F, - const std::vector &ArgVals) { +void Interpreter::callFunction(Function *F, ArrayRef ArgVals) { assert((ECStack.empty() || !ECStack.back().Caller.getInstruction() || ECStack.back().Caller.arg_size() == ArgVals.size()) && "Incorrect number of arguments passed into function call!"); diff --git a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index e2fe065..9b44042 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -49,8 +49,7 @@ using namespace llvm; static ManagedStatic FunctionsLock; -typedef GenericValue (*ExFunc)(FunctionType *, - const std::vector &); +typedef GenericValue (*ExFunc)(FunctionType *, ArrayRef); static ManagedStatic > ExportedFunctions; static ManagedStatic > FuncNames; @@ -178,8 +177,7 @@ static void *ffiValueFor(Type *Ty, const GenericValue &AV, return NULL; } -static bool ffiInvoke(RawFunc Fn, Function *F, - const std::vector &ArgVals, +static bool ffiInvoke(RawFunc Fn, Function *F, ArrayRef ArgVals, const DataLayout *TD, GenericValue &Result) { ffi_cif cif; FunctionType *FTy = F->getFunctionType(); @@ -245,7 +243,7 @@ static bool ffiInvoke(RawFunc Fn, Function *F, #endif // USE_LIBFFI GenericValue Interpreter::callExternalFunction(Function *F, - const std::vector &ArgVals) { + ArrayRef ArgVals) { TheInterpreter = this; unique_lock Guard(*FunctionsLock); @@ -298,9 +296,8 @@ GenericValue Interpreter::callExternalFunction(Function *F, // // void atexit(Function*) -static -GenericValue lle_X_atexit(FunctionType *FT, - const std::vector &Args) { +static GenericValue lle_X_atexit(FunctionType *FT, + ArrayRef Args) { assert(Args.size() == 1); TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0])); GenericValue GV; @@ -309,17 +306,13 @@ GenericValue lle_X_atexit(FunctionType *FT, } // void exit(int) -static -GenericValue lle_X_exit(FunctionType *FT, - const std::vector &Args) { +static GenericValue lle_X_exit(FunctionType *FT, ArrayRef Args) { TheInterpreter->exitCalled(Args[0]); return GenericValue(); } // void abort(void) -static -GenericValue lle_X_abort(FunctionType *FT, - const std::vector &Args) { +static GenericValue lle_X_abort(FunctionType *FT, ArrayRef Args) { //FIXME: should we report or raise here? //report_fatal_error("Interpreted program raised SIGABRT"); raise (SIGABRT); @@ -328,9 +321,8 @@ GenericValue lle_X_abort(FunctionType *FT, // int sprintf(char *, const char *, ...) - a very rough implementation to make // output useful. -static -GenericValue lle_X_sprintf(FunctionType *FT, - const std::vector &Args) { +static GenericValue lle_X_sprintf(FunctionType *FT, + ArrayRef Args) { char *OutputBuffer = (char *)GVTOP(Args[0]); const char *FmtStr = (const char *)GVTOP(Args[1]); unsigned ArgNo = 2; @@ -411,9 +403,8 @@ GenericValue lle_X_sprintf(FunctionType *FT, // int printf(const char *, ...) - a very rough implementation to make output // useful. -static -GenericValue lle_X_printf(FunctionType *FT, - const std::vector &Args) { +static GenericValue lle_X_printf(FunctionType *FT, + ArrayRef Args) { char Buffer[10000]; std::vector NewArgs; NewArgs.push_back(PTOGV((void*)&Buffer[0])); @@ -424,9 +415,8 @@ GenericValue lle_X_printf(FunctionType *FT, } // int sscanf(const char *format, ...); -static -GenericValue lle_X_sscanf(FunctionType *FT, - const std::vector &args) { +static GenericValue lle_X_sscanf(FunctionType *FT, + ArrayRef args) { assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!"); char *Args[10]; @@ -440,9 +430,7 @@ GenericValue lle_X_sscanf(FunctionType *FT, } // int scanf(const char *format, ...); -static -GenericValue lle_X_scanf(FunctionType *FT, - const std::vector &args) { +static GenericValue lle_X_scanf(FunctionType *FT, ArrayRef args) { assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!"); char *Args[10]; @@ -457,9 +445,8 @@ GenericValue lle_X_scanf(FunctionType *FT, // int fprintf(FILE *, const char *, ...) - a very rough implementation to make // output useful. -static -GenericValue lle_X_fprintf(FunctionType *FT, - const std::vector &Args) { +static GenericValue lle_X_fprintf(FunctionType *FT, + ArrayRef Args) { assert(Args.size() >= 2); char Buffer[10000]; std::vector NewArgs; @@ -472,7 +459,7 @@ GenericValue lle_X_fprintf(FunctionType *FT, } static GenericValue lle_X_memset(FunctionType *FT, - const std::vector &Args) { + ArrayRef Args) { int val = (int)Args[1].IntVal.getSExtValue(); size_t len = (size_t)Args[2].IntVal.getZExtValue(); memset((void *)GVTOP(Args[0]), val, len); @@ -484,7 +471,7 @@ static GenericValue lle_X_memset(FunctionType *FT, } static GenericValue lle_X_memcpy(FunctionType *FT, - const std::vector &Args) { + ArrayRef Args) { memcpy(GVTOP(Args[0]), GVTOP(Args[1]), (size_t)(Args[2].IntVal.getLimitedValue())); diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp index 8562981..f103c09 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp @@ -67,7 +67,7 @@ Interpreter::~Interpreter() { void Interpreter::runAtExitHandlers () { while (!AtExitHandlers.empty()) { - callFunction(AtExitHandlers.back(), std::vector()); + callFunction(AtExitHandlers.back(), None); AtExitHandlers.pop_back(); run(); } @@ -75,9 +75,8 @@ void Interpreter::runAtExitHandlers () { /// run - Start execution with the specified function and arguments. /// -GenericValue -Interpreter::runFunction(Function *F, - const std::vector &ArgValues) { +GenericValue Interpreter::runFunction(Function *F, + ArrayRef ArgValues) { assert (F && "Function *F was null at entry to run()"); // Try extra hard not to pass extra args to a function that isn't @@ -87,10 +86,9 @@ Interpreter::runFunction(Function *F, // parameters than it is declared to take. This does not attempt to // take into account gratuitous differences in declared types, // though. - std::vector ActualArgs; - const unsigned ArgCount = F->getFunctionType()->getNumParams(); - for (unsigned i = 0; i < ArgCount; ++i) - ActualArgs.push_back(ArgValues[i]); + const size_t ArgCount = F->getFunctionType()->getNumParams(); + ArrayRef ActualArgs = + ArgValues.slice(0, std::min(ArgValues.size(), ArgCount)); // Set up the function call. callFunction(F, ActualArgs); diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h index 0dc0463..f976641 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h +++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h @@ -127,7 +127,7 @@ public: /// run - Start execution with the specified function and arguments. /// GenericValue runFunction(Function *F, - const std::vector &ArgValues) override; + ArrayRef ArgValues) override; void *getPointerToNamedFunction(StringRef Name, bool AbortOnFailure = true) override { @@ -137,7 +137,7 @@ public: // Methods used to execute code: // Place a call on the stack - void callFunction(Function *F, const std::vector &ArgVals); + void callFunction(Function *F, ArrayRef ArgVals); void run(); // Execute instructions until nothing left to do // Opcode Implementations @@ -194,7 +194,7 @@ public: } GenericValue callExternalFunction(Function *F, - const std::vector &ArgVals); + ArrayRef ArgVals); void exitCalled(GenericValue GV); void addAtExitHandler(Function *F) { diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp index 7e37afe..358d364 100644 --- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -441,8 +441,7 @@ Function *MCJIT::FindFunctionNamed(const char *FnName) { return F; } -GenericValue MCJIT::runFunction(Function *F, - const std::vector &ArgValues) { +GenericValue MCJIT::runFunction(Function *F, ArrayRef ArgValues) { assert(F && "Function *F was null at entry to run()"); void *FPtr = getPointerToFunction(F); diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h index 59e9949..e1d19af 100644 --- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h +++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h @@ -251,7 +251,7 @@ public: void *getPointerToFunction(Function *F) override; GenericValue runFunction(Function *F, - const std::vector &ArgValues) override; + ArrayRef ArgValues) override; /// getPointerToNamedFunction - This method returns the address of the /// specified function by using the dlsym function call. As such it is only diff --git a/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.cpp b/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.cpp index 48fd31e..b7a68e0 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.cpp +++ b/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.cpp @@ -25,7 +25,7 @@ namespace orc { GenericValue OrcMCJITReplacement::runFunction(Function *F, - const std::vector &ArgValues) { + ArrayRef ArgValues) { assert(F && "Function *F was null at entry to run()"); void *FPtr = getPointerToFunction(F); diff --git a/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h b/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h index 4023344..eb39798 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h +++ b/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h @@ -229,7 +229,7 @@ public: } GenericValue runFunction(Function *F, - const std::vector &ArgValues) override; + ArrayRef ArgValues) override; void setObjectCache(ObjectCache *NewCache) override { CompileLayer.setObjectCache(NewCache); -- 2.7.4