Skip to content

Commit

Permalink
Another attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaraldi committed Mar 14, 2023
1 parent fccd950 commit 9323cf2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ FC := $(CROSS_COMPILE)gfortran
ifeq ($(OS), Darwin)
APPLE_ARCH := $(shell uname -m)
ifneq ($(APPLE_ARCH),arm64)
MACOSX_VERSION_MIN := 10.10
MACOSX_VERSION_MIN := 10.14
else
MACOSX_VERSION_MIN := 11.0
endif
Expand Down
4 changes: 4 additions & 0 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,8 @@ struct ShardTimers {
}
};

void emitFloat16Wrappers(Module &M, bool external);

// Perform the actual optimization and emission of the output files
static void add_output_impl(Module &M, TargetMachine &SourceTM, std::string *outputs, ArrayRef<StringRef> names,
NewArchiveMember *unopt, NewArchiveMember *opt, NewArchiveMember *obj, NewArchiveMember *asm_,
Expand Down Expand Up @@ -1014,6 +1016,8 @@ static void add_output_impl(Module &M, TargetMachine &SourceTM, std::string *out
FunctionType::get(Type::getHalfTy(M.getContext()), { Type::getFloatTy(M.getContext()) }, false));
injectCRTAlias(M, "__truncdfhf2", "julia__truncdfhf2",
FunctionType::get(Type::getHalfTy(M.getContext()), { Type::getDoubleTy(M.getContext()) }, false));
#else
emitFloat16Wrappers(M, false);
#endif
}
timers.optimize.stopTimer();
Expand Down
22 changes: 11 additions & 11 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8684,14 +8684,15 @@ static JuliaVariable *julia_const_gv(jl_value_t *val)
return nullptr;
}
//Float16 fun
static void makeCastCall(Module &M, StringRef wrapperName, StringRef calledName, FunctionType *FTwrapper, FunctionType *FTcalled)
static void makeCastCall(Module &M, StringRef wrapperName, StringRef calledName, FunctionType *FTwrapper, FunctionType *FTcalled, bool external)
{
Function *calledFun = M.getFunction(calledName);
if (!calledFun) {
calledFun = Function::Create(FTcalled, Function::ExternalLinkage, calledName, M);
}
auto wrapperFun = Function::Create(FTwrapper, Function::ExternalLinkage, wrapperName, M);

auto linkage = external ? Function::ExternalLinkage : Function::InternalLinkage;
auto wrapperFun = Function::Create(FTwrapper, linkage, wrapperName, M);
wrapperFun->addFnAttr(Attribute::AlwaysInline);
llvm::IRBuilder<> builder(BasicBlock::Create(M.getContext(), "top", wrapperFun));
SmallVector<Value *, 4> CallArgs;
if (wrapperFun->arg_size() != calledFun->arg_size()){
Expand All @@ -8708,28 +8709,27 @@ static void makeCastCall(Module &M, StringRef wrapperName, StringRef calledName,
builder.CreateRet(retval);
}

static void emitFloat16Wrappers(Module &M)
void emitFloat16Wrappers(Module &M, bool external)
{
auto &ctx = M.getContext();
makeCastCall(M, "__gnu_h2f_ieee", "julia__gnu_h2f_ieee", FunctionType::get(Type::getFloatTy(ctx), { Type::getHalfTy(ctx) }, false),
FunctionType::get(Type::getFloatTy(ctx), { Type::getInt16Ty(ctx) }, false));
FunctionType::get(Type::getFloatTy(ctx), { Type::getInt16Ty(ctx) }, false), external);
makeCastCall(M, "__extendhfsf2", "julia__gnu_h2f_ieee", FunctionType::get(Type::getFloatTy(ctx), { Type::getHalfTy(ctx) }, false),
FunctionType::get(Type::getFloatTy(ctx), { Type::getInt16Ty(ctx) }, false));
FunctionType::get(Type::getFloatTy(ctx), { Type::getInt16Ty(ctx) }, false), external);
makeCastCall(M, "__gnu_f2h_ieee", "julia__gnu_f2h_ieee", FunctionType::get(Type::getHalfTy(ctx), { Type::getFloatTy(ctx) }, false),
FunctionType::get(Type::getInt16Ty(ctx), { Type::getFloatTy(ctx) }, false));
FunctionType::get(Type::getInt16Ty(ctx), { Type::getFloatTy(ctx) }, false), external);
makeCastCall(M, "__truncsfhf2", "julia__gnu_f2h_ieee", FunctionType::get(Type::getHalfTy(ctx), { Type::getFloatTy(ctx) }, false),
FunctionType::get(Type::getInt16Ty(ctx), { Type::getFloatTy(ctx) }, false));
FunctionType::get(Type::getInt16Ty(ctx), { Type::getFloatTy(ctx) }, false), external);
makeCastCall(M, "__truncdfhf2", "julia__truncdfhf2", FunctionType::get(Type::getHalfTy(ctx), { Type::getDoubleTy(ctx) }, false),
FunctionType::get(Type::getInt16Ty(ctx), { Type::getDoubleTy(ctx) }, false));

FunctionType::get(Type::getInt16Ty(ctx), { Type::getDoubleTy(ctx) }, false), external);
}

static void init_f16_funcs(void)
{
auto ctx = jl_ExecutionEngine->acquireContext();
auto TSM = jl_create_ts_module("F16Wrappers", ctx, imaging_default());
auto aliasM = TSM.getModuleUnlocked();
emitFloat16Wrappers(*aliasM);
emitFloat16Wrappers(*aliasM, true);
jl_ExecutionEngine->addModule(std::move(TSM));
}

Expand Down
12 changes: 5 additions & 7 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,16 +1340,14 @@ JuliaOJIT::JuliaOJIT()
}

JD.addToLinkOrder(GlobalJD, orc::JITDylibLookupFlags::MatchExportedSymbolsOnly);
#if JL_LLVM_VERSION <= 140000
orc::SymbolAliasMap jl_crt = {
{ mangle("__gnu_h2f_ieee"), { mangle("julia__gnu_h2f_ieee"), JITSymbolFlags::Exported } },
{ mangle("__extendhfsf2"), { mangle("julia__gnu_h2f_ieee"), JITSymbolFlags::Exported } },
{ mangle("__gnu_f2h_ieee"), { mangle("julia__gnu_f2h_ieee"), JITSymbolFlags::Exported } },
{ mangle("__truncsfhf2"), { mangle("julia__gnu_f2h_ieee"), JITSymbolFlags::Exported } },
{ mangle("__truncdfhf2"), { mangle("julia__truncdfhf2"), JITSymbolFlags::Exported } }
{ mangle("__gnu_h2f_ieee"), { mangle("__jl_half2float"), JITSymbolFlags::Exported } },
{ mangle("__extendhfsf2"), { mangle("__jl_half2float"), JITSymbolFlags::Exported } },
{ mangle("__gnu_f2h_ieee"), { mangle("__jl_float2half"), JITSymbolFlags::Exported } },
{ mangle("__truncsfhf2"), { mangle("__jl_float2half"), JITSymbolFlags::Exported } },
{ mangle("__truncdfhf2"), { mangle("__jl_double2half"), JITSymbolFlags::Exported } }
};
cantFail(GlobalJD.define(orc::symbolAliases(jl_crt)));
#endif

#ifdef MSAN_EMUTLS_WORKAROUND
orc::SymbolMap msan_crt;
Expand Down

0 comments on commit 9323cf2

Please sign in to comment.