static void make_rdtscp(compile_t* c) { if(target_is_x86(c->opt->triple)) { // i64 @llvm.x86.rdtscp(i8*) LLVMTypeRef f_type = LLVMFunctionType(c->i64, &c->void_ptr, 1, false); LLVMValueRef rdtscp = LLVMAddFunction(c->module, "llvm.x86.rdtscp", f_type); // i64 @internal.x86.rdtscp(i32*) LLVMTypeRef i32_ptr = LLVMPointerType(c->i32, 0); f_type = LLVMFunctionType(c->i64, &i32_ptr, 1, false); LLVMValueRef fun = codegen_addfun(c, "internal.x86.rdtscp", f_type); LLVMSetFunctionCallConv(fun, LLVMCCallConv); codegen_startfun(c, fun, NULL, NULL); // Cast i32* to i8* and call the intrinsic. LLVMValueRef arg = LLVMGetParam(fun, 0); arg = LLVMBuildBitCast(c->builder, arg, c->void_ptr, ""); LLVMValueRef result = LLVMBuildCall(c->builder, rdtscp, &arg, 1, ""); LLVMBuildRet(c->builder, result); codegen_finishfun(c); } else { (void)c; } }
static void platform_x86(compile_t* c, reach_type_t* t) { FIND_METHOD("x86"); start_function(c, m, c->ibool, &t->use_type, 1); LLVMValueRef result = LLVMConstInt(c->ibool, target_is_x86(c->opt->triple), false); LLVMBuildRet(c->builder, result); codegen_finishfun(c); BOX_FUNCTION(); }
static void make_cpuid(compile_t* c) { if(target_is_x86(c->opt->triple)) { LLVMTypeRef elems[4] = {c->i32, c->i32, c->i32, c->i32}; LLVMTypeRef r_type = LLVMStructTypeInContext(c->context, elems, 4, false); LLVMTypeRef f_type = LLVMFunctionType(r_type, &c->i32, 1, false); LLVMValueRef fun = codegen_addfun(c, "internal.x86.cpuid", f_type); LLVMSetFunctionCallConv(fun, LLVMCCallConv); codegen_startfun(c, fun, NULL, NULL); LLVMValueRef cpuid = LLVMConstInlineAsm(f_type, "cpuid", "={ax},={bx},={cx},={dx},{ax}", false, false); LLVMValueRef zero = LLVMConstInt(c->i32, 0, false); LLVMValueRef result = LLVMBuildCall(c->builder, cpuid, &zero, 1, ""); LLVMBuildRet(c->builder, result); codegen_finishfun(c); } else { (void)c; } }
// Report whether the named platform attribute is true bool os_is_target(const char* attribute, bool release, bool* out_is_target, pass_opt_t* options) { pony_assert(attribute != NULL); pony_assert(out_is_target != NULL); pony_assert(options != NULL); if(!strcmp(attribute, OS_BSD_NAME)) { *out_is_target = target_is_bsd(options->triple); return true; } if(!strcmp(attribute, OS_FREEBSD_NAME)) { *out_is_target = target_is_freebsd(options->triple); return true; } if(!strcmp(attribute, OS_DRAGONFLY_NAME)) { *out_is_target = target_is_dragonfly(options->triple); return true; } if(!strcmp(attribute, OS_LINUX_NAME)) { *out_is_target = target_is_linux(options->triple); return true; } if(!strcmp(attribute, OS_MACOSX_NAME)) { *out_is_target = target_is_macosx(options->triple); return true; } if(!strcmp(attribute, OS_WINDOWS_NAME)) { *out_is_target = target_is_windows(options->triple); return true; } if(!strcmp(attribute, OS_POSIX_NAME)) { *out_is_target = target_is_posix(options->triple); return true; } if(!strcmp(attribute, OS_X86_NAME)) { *out_is_target = target_is_x86(options->triple); return true; } if(!strcmp(attribute, OS_ARM_NAME)) { *out_is_target = target_is_arm(options->triple); return true; } if(!strcmp(attribute, OS_LP64_NAME)) { *out_is_target = target_is_lp64(options->triple); return true; } if(!strcmp(attribute, OS_LLP64_NAME)) { *out_is_target = target_is_llp64(options->triple); return true; } if(!strcmp(attribute, OS_ILP32_NAME)) { *out_is_target = target_is_ilp32(options->triple); return true; } if(!strcmp(attribute, OS_NATIVE128_NAME)) { *out_is_target = target_is_native128(options->triple); return true; } if(!strcmp(attribute, OS_DEBUG_NAME)) { *out_is_target = !release; return true; } return false; }