Skip to content

Commit

Permalink
fixup! preexecuter: replace getPointerElementType usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyxogen committed Feb 14, 2024
1 parent d04cccf commit 153b4b7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 41 deletions.
49 changes: 22 additions & 27 deletions llvm/lib/CheerpWriter/PreExecute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ static char* most_derived_pointer(char* Addr) {
return it->first;
}

static GenericValue pre_execute_pointer_base(Function *F,
static GenericValue pre_execute_pointer_base(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
char *p = (char *)(currentEE->GVTORP(Args[0]));
return currentEE->RPTOGV(most_derived_pointer(p));
}

static GenericValue pre_execute_pointer_offset(Function *F,
static GenericValue pre_execute_pointer_offset(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
GenericValue G;
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
Expand All @@ -88,9 +88,8 @@ static GenericValue pre_execute_pointer_offset(Function *F,
return G;
}

static GenericValue pre_execute_allocate_array(Function *F,
static GenericValue pre_execute_allocate_array(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
FunctionType *FT = F->getFunctionType();
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
size_t size=(size_t)(Args[1].IntVal.getLimitedValue());

Expand Down Expand Up @@ -123,9 +122,8 @@ static GenericValue pre_execute_allocate_array(Function *F,
return currentEE->RPTOGV(ret);
}

static GenericValue pre_execute_allocate(Function *F,
static GenericValue pre_execute_allocate(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
FunctionType *FT = F->getFunctionType();
size_t size=(size_t)(Args[1].IntVal.getLimitedValue());
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
void* ret = PreExecute::currentPreExecutePass->allocator->allocate(size);
Expand All @@ -144,9 +142,8 @@ static GenericValue pre_execute_allocate(Function *F,
return currentEE->RPTOGV(ret);
}

static GenericValue pre_execute_reallocate(Function *F,
static GenericValue pre_execute_reallocate(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
FunctionType *FT = F->getFunctionType();
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
void *p = (void *)(currentEE->GVTORP(Args[0]));
size_t size=(size_t)(Args[1].IntVal.getLimitedValue());
Expand Down Expand Up @@ -182,7 +179,7 @@ static GenericValue pre_execute_reallocate(Function *F,
return currentEE->RPTOGV(ret);
}

static GenericValue pre_execute_deallocate(Function *F,
static GenericValue pre_execute_deallocate(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
#ifdef DEBUG_PRE_EXECUTE
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
Expand All @@ -198,9 +195,8 @@ static GenericValue pre_execute_deallocate(Function *F,
return GenericValue();
}

static GenericValue pre_execute_get_array_len(Function *F,
static GenericValue pre_execute_get_array_len(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
FunctionType *FT = F->getFunctionType();
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
const DataLayout& DL = currentEE->getDataLayout();
assert(Attrs.hasParamAttr(0, Attribute::ElementType) && "ElementType attribute not present on call");
Expand All @@ -214,12 +210,12 @@ static GenericValue pre_execute_get_array_len(Function *F,
return G;
}

static GenericValue pre_execute_cast(Function *F,
static GenericValue pre_execute_cast(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
return Args[0];
}

static GenericValue pre_execute_memcpy(Function *F,
static GenericValue pre_execute_memcpy(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
// Support fully typed memcpy
Expand All @@ -231,7 +227,7 @@ static GenericValue pre_execute_memcpy(Function *F,
return GV;
}

static GenericValue pre_execute_memmove(Function *F,
static GenericValue pre_execute_memmove(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
// Support fully typed memmove
Expand All @@ -243,7 +239,7 @@ static GenericValue pre_execute_memmove(Function *F,
return GV;
}

static GenericValue pre_execute_memset(Function *F,
static GenericValue pre_execute_memset(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
// Support fully typed memset
Expand All @@ -256,7 +252,7 @@ static GenericValue pre_execute_memset(Function *F,
return GV;
}

static GenericValue pre_execute_umax(Function *F,
static GenericValue pre_execute_umax(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
GenericValue GV;
if(Args[0].IntVal.ugt(Args[1].IntVal))
Expand All @@ -266,7 +262,7 @@ static GenericValue pre_execute_umax(Function *F,
return GV;
}

static GenericValue pre_execute_smax(Function *F,
static GenericValue pre_execute_smax(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
GenericValue GV;
if(Args[0].IntVal.sgt(Args[1].IntVal))
Expand All @@ -276,9 +272,8 @@ static GenericValue pre_execute_smax(Function *F,
return GV;
}

static GenericValue pre_execute_abs(Function *F,
static GenericValue pre_execute_abs(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
FunctionType *FT = F->getFunctionType();
GenericValue GV;
if(Args[0].IntVal.sgt(APInt(FT->getReturnType()->isIntegerTy(32) ? 32 : 64, 0)))
GV.IntVal = Args[0].IntVal;
Expand All @@ -287,7 +282,7 @@ static GenericValue pre_execute_abs(Function *F,
return GV;
}

static GenericValue pre_execute_umin(Function *F,
static GenericValue pre_execute_umin(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
GenericValue GV;
if(Args[0].IntVal.ult(Args[1].IntVal))
Expand All @@ -297,7 +292,7 @@ static GenericValue pre_execute_umin(Function *F,
return GV;
}

static GenericValue pre_execute_smin(Function *F,
static GenericValue pre_execute_smin(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
GenericValue GV;
if(Args[0].IntVal.slt(Args[1].IntVal))
Expand Down Expand Up @@ -402,7 +397,7 @@ static bool get_subobject_byte_offset(StructType* derivedType, uint32_t baseInde
return false;
}

static GenericValue pre_execute_downcast_current(Function *F,
static GenericValue pre_execute_downcast_current(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {

ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
Expand Down Expand Up @@ -431,7 +426,7 @@ static GenericValue pre_execute_downcast_current(Function *F,
return ret;
}

static GenericValue pre_execute_downcast(Function *F,
static GenericValue pre_execute_downcast(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
// We need to apply the offset in bytes using the bases metadata
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
Expand Down Expand Up @@ -465,7 +460,7 @@ static GenericValue pre_execute_downcast(Function *F,
return currentEE->RPTOGV(derivedAddr + byteOffset);
}

static GenericValue pre_execute_virtualcast(Function *F,
static GenericValue pre_execute_virtualcast(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
// We need to apply the offset in bytes using the bases metadata
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
Expand All @@ -490,12 +485,12 @@ static GenericValue pre_execute_virtualcast(Function *F,
return currentEE->RPTOGV(derivedAddr + byteOffset);
}

static GenericValue pre_execute_upcast(Function *F,
static GenericValue pre_execute_upcast(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
return Args[0];
}

static GenericValue assertEqualImpl(Function *F,
static GenericValue assertEqualImpl(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs)
{
ExecutionEngine *currentEE = PreExecute::currentPreExecutePass->currentEE;
Expand All @@ -511,7 +506,7 @@ static GenericValue assertEqualImpl(Function *F,
return GenericValue(0);
}

static GenericValue emptyFunction(Function *F,
static GenericValue emptyFunction(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs)
{
return GenericValue(0);
Expand Down
28 changes: 14 additions & 14 deletions llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ using namespace llvm;

namespace {

typedef GenericValue (*ExFunc)(Function *, ArrayRef<GenericValue>, AttributeList);
typedef GenericValue (*ExFunc)(FunctionType *, ArrayRef<GenericValue>, AttributeList);
typedef void (*RawFunc)();

struct Functions {
Expand Down Expand Up @@ -285,7 +285,7 @@ GenericValue Interpreter::callExternalFunction(Function *F,
if (ExFunc Fn = (FI == Fns.ExportedFunctions.end()) ? lookupFunction(F, LazyFunctionCreator)
: FI->second) {
Guard.unlock();
return Fn(F, ArgVals, CallerFrame.Caller->getAttributes());
return Fn(F->getFunctionType(), ArgVals, CallerFrame.Caller->getAttributes());
}

#ifdef USE_LIBFFI
Expand Down Expand Up @@ -332,7 +332,7 @@ GenericValue Interpreter::callExternalFunction(Function *F,
//

// void atexit(Function*)
static GenericValue lle_X_atexit(Function *F,
static GenericValue lle_X_atexit(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList /*unused*/) {
assert(Args.size() == 1);
TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0]));
Expand All @@ -342,13 +342,13 @@ static GenericValue lle_X_atexit(Function *F,
}

// void exit(int)
static GenericValue lle_X_exit(Function *F, ArrayRef<GenericValue> Args, AttributeList /*unused*/) {
static GenericValue lle_X_exit(FunctionType *FT, ArrayRef<GenericValue> Args, AttributeList /*unused*/) {
TheInterpreter->exitCalled(Args[0]);
return GenericValue();
}

// void abort(void)
static GenericValue lle_X_abort(Function *F, ArrayRef<GenericValue> Args, AttributeList /*unused*/) {
static GenericValue lle_X_abort(FunctionType *FT, ArrayRef<GenericValue> Args, AttributeList /*unused*/) {
//FIXME: should we report or raise here?
//report_fatal_error("Interpreted program raised SIGABRT");
raise (SIGABRT);
Expand All @@ -357,7 +357,7 @@ static GenericValue lle_X_abort(Function *F, ArrayRef<GenericValue> Args, Attrib

// int sprintf(char *, const char *, ...) - a very rough implementation to make
// output useful.
static GenericValue lle_X_sprintf(Function *F,
static GenericValue lle_X_sprintf(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList /*unused*/) {
char *OutputBuffer = (char *)GVTOP(Args[0]);
const char *FmtStr = (const char *)GVTOP(Args[1]);
Expand Down Expand Up @@ -439,19 +439,19 @@ static GenericValue lle_X_sprintf(Function *F,

// int printf(const char *, ...) - a very rough implementation to make output
// useful.
static GenericValue lle_X_printf(Function *F,
static GenericValue lle_X_printf(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
char Buffer[10000];
std::vector<GenericValue> NewArgs;
NewArgs.push_back(PTOGV((void*)&Buffer[0]));
llvm::append_range(NewArgs, Args);
GenericValue GV = lle_X_sprintf(F, NewArgs, Attrs);
GenericValue GV = lle_X_sprintf(FT, NewArgs, Attrs);
outs() << Buffer;
return GV;
}

// int sscanf(const char *format, ...);
static GenericValue lle_X_sscanf(Function *F,
static GenericValue lle_X_sscanf(FunctionType *FT,
ArrayRef<GenericValue> args, AttributeList /*unused*/) {
assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");

Expand All @@ -466,7 +466,7 @@ static GenericValue lle_X_sscanf(Function *F,
}

// int scanf(const char *format, ...);
static GenericValue lle_X_scanf(Function *F, ArrayRef<GenericValue> args, AttributeList /*unused*/) {
static GenericValue lle_X_scanf(FunctionType *FT, ArrayRef<GenericValue> args, AttributeList /*unused*/) {
assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!");

char *Args[10];
Expand All @@ -481,20 +481,20 @@ static GenericValue lle_X_scanf(Function *F, ArrayRef<GenericValue> args, Attrib

// int fprintf(FILE *, const char *, ...) - a very rough implementation to make
// output useful.
static GenericValue lle_X_fprintf(Function *F,
static GenericValue lle_X_fprintf(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList Attrs) {
assert(Args.size() >= 2);
char Buffer[10000];
std::vector<GenericValue> NewArgs;
NewArgs.push_back(PTOGV(Buffer));
NewArgs.insert(NewArgs.end(), Args.begin()+1, Args.end());
GenericValue GV = lle_X_sprintf(F, NewArgs, Attrs);
GenericValue GV = lle_X_sprintf(FT, NewArgs, Attrs);

fputs(Buffer, (FILE *) GVTOP(Args[0]));
return GV;
}

static GenericValue lle_X_memset(Function *F,
static GenericValue lle_X_memset(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList /*unused*/) {
int val = (int)Args[1].IntVal.getSExtValue();
size_t len = (size_t)Args[2].IntVal.getZExtValue();
Expand All @@ -506,7 +506,7 @@ static GenericValue lle_X_memset(Function *F,
return GV;
}

static GenericValue lle_X_memcpy(Function *F,
static GenericValue lle_X_memcpy(FunctionType *FT,
ArrayRef<GenericValue> Args, AttributeList /*unused*/) {
memcpy(GVTOP(Args[0]), GVTOP(Args[1]),
(size_t)(Args[2].IntVal.getLimitedValue()));
Expand Down

0 comments on commit 153b4b7

Please sign in to comment.