Skip to content

Commit a78930b

Browse files
Maqrkkyuri91
authored andcommitted
Add builtin for thread setup rejection
The previous builtin for the thread setup resolve is changed to now return an object, like the new one for thread setup rejection.
1 parent 9c20615 commit a78930b

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

clang/include/clang/Basic/BuiltinsCheerp.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ BUILTIN(__builtin_cheerp_get_threading_object, "", "B")
4141
BUILTIN(__builtin_cheerp_get_threading_blob, "", "B")
4242
BUILTIN(__builtin_cheerp_set_thread_pointer, "vUi", "")
4343
BUILTIN(__builtin_cheerp_get_thread_pointer, "Ui", "")
44+
BUILTIN(__builtin_cheerp_get_thread_setup_resolve, "", "B")
45+
BUILTIN(__builtin_cheerp_get_thread_setup_reject, "", "B")
4446
BUILTIN(__builtin_cheerp_atomic_wait, "iv*iLLi", "")
4547
BUILTIN(__builtin_cheerp_atomic_notify, "iv*i", "")
46-
BUILTIN(__builtin_cheerp_thread_setup_resolve, "v", "")
4748

4849
// SIMD builtins
4950
TARGET_BUILTIN(__builtin_wasm_swizzle_i8x16, "V16ScV16ScV16Sc", "nc", "simd128")

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12568,6 +12568,16 @@ Value *CodeGenFunction::EmitCheerpBuiltinExpr(unsigned BuiltinID,
1256812568
Function *F = CGM.getIntrinsic(Intrinsic::cheerp_get_threading_blob, Tys);
1256912569
return Builder.CreateCall(F, Ops);
1257012570
}
12571+
else if (BuiltinID == Cheerp::BI__builtin_cheerp_get_thread_setup_resolve) {
12572+
llvm::Type *Tys[] = { ConvertType(E->getType()) };
12573+
Function *F = CGM.getIntrinsic(Intrinsic::cheerp_get_thread_setup_resolve, Tys);
12574+
return Builder.CreateCall(F, Ops);
12575+
}
12576+
else if (BuiltinID == Cheerp::BI__builtin_cheerp_get_thread_setup_reject) {
12577+
llvm::Type *Tys[] = { ConvertType(E->getType()) };
12578+
Function *F = CGM.getIntrinsic(Intrinsic::cheerp_get_thread_setup_reject, Tys);
12579+
return Builder.CreateCall(F, Ops);
12580+
}
1257112581
else if (BuiltinID == Cheerp::BI__builtin_cheerp_stack_save) {
1257212582
Function *F = CGM.getIntrinsic(Intrinsic::stacksave);
1257312583
return Builder.CreateCall(F, Ops);

llvm/include/llvm/Cheerp/NameGenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class NameGenerator
8484
BLOBNAME,
8585
THREADSETUPPROMISE,
8686
THREADSETUPRESOLVE,
87+
THREADSETUPREJECT,
8788
MEMORY,
8889
HEAP8,
8990
HEAP16,

llvm/include/llvm/IR/IntrinsicsCheerp.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def int_cheerp_set_thread_pointer : Intrinsic<[],
108108
def int_cheerp_get_threadlocal_offset : Intrinsic<[llvm_i32_ty],
109109
[llvm_anyptr_ty]>;
110110

111+
def int_cheerp_get_thread_setup_resolve : Intrinsic<[llvm_anyptr_ty]>;
112+
113+
def int_cheerp_get_thread_setup_reject : Intrinsic<[llvm_anyptr_ty]>;
114+
111115
def int_cheerp_atomic_wait : Intrinsic<[llvm_i32_ty],
112116
[llvm_ptr_ty, llvm_i32_ty, llvm_i64_ty]>,
113117
ClangBuiltin<"__builtin_cheerp_atomic_wait">;
@@ -116,10 +120,6 @@ def int_cheerp_atomic_notify : Intrinsic<[llvm_i32_ty],
116120
[llvm_ptr_ty, llvm_i32_ty]>,
117121
ClangBuiltin<"__builtin_cheerp_atomic_notify">;
118122

119-
def int_cheerp_thread_setup_resolve : Intrinsic<[],
120-
[]>,
121-
ClangBuiltin<"__builtin_cheerp_thread_setup_resolve">;
122-
123123
def int_cheerp_environ : Intrinsic<[llvm_anyptr_ty]>;
124124

125125
def int_cheerp_argv : Intrinsic<[llvm_anyptr_ty]>;

llvm/lib/CheerpWriter/CheerpWriter.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -977,10 +977,16 @@ CheerpWriter::COMPILE_INSTRUCTION_FEEDBACK CheerpWriter::handleBuiltinCall(const
977977
stream << "new Blob([" << threadingObject << "." << blobText << "])";
978978
return COMPILE_OK;
979979
}
980-
else if(intrinsicId==Intrinsic::cheerp_thread_setup_resolve)
980+
else if(intrinsicId==Intrinsic::cheerp_get_thread_setup_resolve)
981981
{
982982
StringRef threadSetupResolve = namegen.getBuiltinName(NameGenerator::Builtin::THREADSETUPRESOLVE);
983-
stream << threadSetupResolve << "();" << NewLine;
983+
stream << threadSetupResolve;
984+
return COMPILE_OK;
985+
}
986+
else if(intrinsicId==Intrinsic::cheerp_get_thread_setup_reject)
987+
{
988+
StringRef threadSetupReject = namegen.getBuiltinName(NameGenerator::Builtin::THREADSETUPREJECT);
989+
stream << threadSetupReject;
984990
return COMPILE_OK;
985991
}
986992
else if(intrinsicId==Intrinsic::abs)
@@ -7153,8 +7159,10 @@ void CheerpWriter::compileThreadingObject()
71537159
// First create the promise and resolve variables for threading setup.
71547160
StringRef threadPromise = namegen.getBuiltinName(NameGenerator::Builtin::THREADSETUPPROMISE);
71557161
StringRef threadResolve = namegen.getBuiltinName(NameGenerator::Builtin::THREADSETUPRESOLVE);
7162+
StringRef threadReject = namegen.getBuiltinName(NameGenerator::Builtin::THREADSETUPREJECT);
71567163
stream << "var " << threadResolve << "=null;" << NewLine;
7157-
stream << "var " << threadPromise << "=new Promise((r)=>{" << threadResolve << "=r;});" << NewLine;
7164+
stream << "var " << threadReject << "=null;" << NewLine;
7165+
stream << "var " << threadPromise << "=new Promise((f,r)=>{" << threadResolve << "=f;" << threadReject << "=r});" << NewLine;
71587166

71597167
// Then create the rest of the threading variables.
71607168
StringRef threadObject = namegen.getBuiltinName(NameGenerator::Builtin::THREADINGOBJECT);

llvm/lib/CheerpWriter/NameGenerator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ void NameGenerator::generateReadableNames(const Module& M, const GlobalDepsAnaly
697697
builtins[BLOBNAME] = "blobText";
698698
builtins[THREADSETUPPROMISE] = "__threadSetupPromise";
699699
builtins[THREADSETUPRESOLVE] = "__threadSetupResolve";
700+
builtins[THREADSETUPREJECT] = "__threadSetupReject";
700701
builtins[HEAP8] = "HEAP8";
701702
builtins[HEAP16] = "HEAP16";
702703
builtins[HEAP32] = "HEAP32";

0 commit comments

Comments
 (0)