Go to the documentation of this file.
24 #include "llvm/Config/config.h"
67 typedef void (*RawFunc)();
103 std::string ExtName =
"lle_";
108 ExtName += (
"_" +
F->getName()).str();
111 ExFunc FnPtr = (*FuncNames)[ExtName];
113 FnPtr = (*FuncNames)[(
"lle_X_" +
F->getName()).str()];
116 (
"lle_X_" +
F->getName()).str());
123 static ffi_type *ffiTypeFor(
Type *Ty) {
128 case 8:
return &ffi_type_sint8;
129 case 16:
return &ffi_type_sint16;
130 case 32:
return &ffi_type_sint32;
131 case 64:
return &ffi_type_sint64;
150 int8_t *I8Ptr = (int8_t *) ArgDataPtr;
155 int16_t *I16Ptr = (int16_t *) ArgDataPtr;
160 int32_t *I32Ptr = (int32_t *) ArgDataPtr;
165 int64_t *I64Ptr = (int64_t *) ArgDataPtr;
172 float *FloatPtr = (
float *) ArgDataPtr;
177 double *DoublePtr = (
double *) ArgDataPtr;
182 void **PtrPtr = (
void **) ArgDataPtr;
197 const unsigned NumArgs =
F->arg_size();
201 if (ArgVals.
size() > NumArgs &&
F->isVarArg()) {
203 +
"' is not supported by the Interpreter.");
206 unsigned ArgBytes = 0;
208 std::vector<ffi_type*> args(NumArgs);
211 const unsigned ArgNo =
A->getArgNo();
213 args[ArgNo] = ffiTypeFor(ArgTy);
219 uint8_t *ArgDataPtr = ArgData.data();
223 const unsigned ArgNo =
A->getArgNo();
225 values[ArgNo] = ffiValueFor(ArgTy, ArgVals[ArgNo], ArgDataPtr);
230 ffi_type *rtype = ffiTypeFor(RetTy);
232 if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, NumArgs, rtype, args.data()) ==
237 ffi_call(&cif, Fn,
ret.data(),
values.data());
242 case 16:
Result.IntVal =
APInt(16, *(int16_t*)
ret.data());
break;
243 case 32:
Result.IntVal =
APInt(32, *(int32_t*)
ret.data());
break;
244 case 64:
Result.IntVal =
APInt(64, *(int64_t*)
ret.data());
break;
271 return Fn(
F->getFunctionType(), ArgVals);
275 std::map<const Function *, RawFunc>::iterator RF = RawFunctions->find(
F);
277 if (RF == RawFunctions->end()) {
283 RawFunctions->insert(std::make_pair(
F, RawFn));
291 if (RawFn != 0 && ffiInvoke(RawFn,
F, ArgVals,
getDataLayout(), Result))
295 if (
F->getName() ==
"__main")
296 errs() <<
"Tried to execute an unknown external function: "
297 << *
F->getType() <<
" __main\n";
302 errs() <<
"Recompiling LLVM with --enable-libffi might help.\n";
339 char *OutputBuffer = (
char *)
GVTOP(
Args[0]);
340 const char *FmtStr = (
const char *)
GVTOP(
Args[1]);
351 sprintf(OutputBuffer++,
"%c", *FmtStr++);
354 sprintf(OutputBuffer,
"%c%c", *FmtStr, *(FmtStr+1));
355 FmtStr += 2; OutputBuffer += 2;
359 char FmtBuf[100] =
"", Buffer[1000] =
"";
362 char Last = *FB++ = *FmtStr++;
363 unsigned HowLong = 0;
364 while (Last !=
'c' && Last !=
'd' && Last !=
'i' && Last !=
'u' &&
365 Last !=
'o' && Last !=
'x' && Last !=
'X' && Last !=
'e' &&
366 Last !=
'E' && Last !=
'g' && Last !=
'G' && Last !=
'f' &&
367 Last !=
'p' && Last !=
's' && Last !=
'%') {
368 if (Last ==
'l' || Last ==
'L') HowLong++;
369 Last = *FB++ = *FmtStr++;
375 memcpy(Buffer,
"%", 2);
break;
385 sizeof(
long) <
sizeof(int64_t)) {
388 unsigned Size = strlen(FmtBuf);
389 FmtBuf[Size] = FmtBuf[Size-1];
391 FmtBuf[Size-1] =
'l';
393 sprintf(Buffer, FmtBuf,
Args[ArgNo++].
IntVal.getZExtValue());
397 case 'e':
case 'E':
case 'g':
case 'G':
case 'f':
398 sprintf(Buffer, FmtBuf,
Args[ArgNo++].DoubleVal);
break;
400 sprintf(Buffer, FmtBuf, (
void*)
GVTOP(
Args[ArgNo++]));
break;
402 sprintf(Buffer, FmtBuf, (
char*)
GVTOP(
Args[ArgNo++]));
break;
404 errs() <<
"<unknown printf code '" << *FmtStr <<
"'!>";
407 size_t Len = strlen(Buffer);
408 memcpy(OutputBuffer, Buffer, Len + 1);
422 std::vector<GenericValue> NewArgs;
423 NewArgs.push_back(
PTOGV((
void*)&Buffer[0]));
433 assert(args.
size() < 10 &&
"Only handle up to 10 args to sscanf right now!");
436 for (
unsigned i = 0;
i < args.
size(); ++
i)
447 assert(args.
size() < 10 &&
"Only handle up to 10 args to scanf right now!");
450 for (
unsigned i = 0;
i < args.
size(); ++
i)
465 std::vector<GenericValue> NewArgs;
466 NewArgs.push_back(
PTOGV(Buffer));
467 NewArgs.insert(NewArgs.end(),
Args.begin()+1,
Args.end());
477 size_t len = (size_t)
Args[2].
IntVal.getZExtValue();
498 void Interpreter::initializeExternalFunctions() {
This class represents an incoming formal argument to a Function.
@ FloatTyID
32-bit floating point type
@ DoubleTyID
64-bit floating point type
This is an optimization pass for GlobalISel generic memory operations.
A parsed version of the target data layout string in and methods for querying it.
@ VoidTyID
type with no size
static Interpreter * TheInterpreter
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
static GenericValue lle_X_atexit(FunctionType *FT, ArrayRef< GenericValue > Args)
TypeID getTypeID() const
Return the type id for the type.
static GenericValue lle_X_exit(FunctionType *FT, ArrayRef< GenericValue > Args)
static ExFunc lookupFunction(const Function *F)
The instances of the Type class are immutable: once they are created, they are never changed.
to esp esp setne al movzbw ax esp setg cl movzbw cx cmove cx cl jne LBB1_2 esp ret(also really horrible code on ppc). This is due to the expand code for 64-bit compares. GCC produces multiple branches
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static GenericValue lle_X_sprintf(FunctionType *FT, ArrayRef< GenericValue > Args)
static GenericValue lle_X_sscanf(FunctionType *FT, ArrayRef< GenericValue > args)
void addAtExitHandler(Function *F)
void exitCalled(GenericValue GV)
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
void * GVTOP(const GenericValue &GV)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
uint64_t getZExtValue() const
Get zero extended value.
ArrayRef< Type * > params() const
static GenericValue lle_X_memcpy(FunctionType *FT, ArrayRef< GenericValue > Args)
static ManagedStatic< std::map< const Function *, ExFunc > > ExportedFunctions
static void * SearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName.
static ManagedStatic< std::map< std::string, ExFunc > > FuncNames
const DataLayout & getDataLayout() const
The initial backend is deliberately restricted to z10 We should add support for later architectures at some point If an asm ties an i32 r result to an i64 the input will be treated as an leaving the upper bits uninitialised For i64 store i32 val
static ManagedStatic< sys::Mutex > FunctionsLock
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
SmartScopedLock< false > ScopedLock
GenericValue(* ExFunc)(FunctionType *, ArrayRef< GenericValue >)
Type * getParamType(unsigned i) const
Parameter type accessors.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
static GenericValue lle_X_abort(FunctionType *FT, ArrayRef< GenericValue > Args)
Class for arbitrary precision integers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
@ IntegerTyID
Arbitrary bit width integers.
static GenericValue lle_X_fprintf(FunctionType *FT, ArrayRef< GenericValue > Args)
static char getTypeID(Type *Ty)
void * getPointerToGlobalIfAvailable(StringRef S)
getPointerToGlobalIfAvailable - This returns the address of the specified global value if it is has a...
GenericValue PTOGV(void *P)
static GenericValue lle_X_scanf(FunctionType *FT, ArrayRef< GenericValue > args)
size_t size() const
size - Get the array size.
GenericValue callExternalFunction(Function *F, ArrayRef< GenericValue > ArgVals)
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static GenericValue lle_X_memset(FunctionType *FT, ArrayRef< GenericValue > Args)
static GenericValue lle_X_printf(FunctionType *FT, ArrayRef< GenericValue > Args)
Type * getReturnType() const
Class to represent function types.