Skip to content

Commit

Permalink
Add more builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-fink committed Nov 23, 2023
1 parent 414ce81 commit 0c6f055
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/BuiltinsWebAssembly.def
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ BUILTIN(__builtin_wasm_max_f64, "ddd", "nc")

BUILTIN(__builtin_wasm_segment_new, "v*v*z", "n")
BUILTIN(__builtin_wasm_segment_free, "vv*z", "n")
BUILTIN(__builtin_wasm_segment_set_tag, "vv*v*z", "n")
BUILTIN(__builtin_wasm_untag_ptr, "v*v*", "n")

// Exception handling builtins.
TARGET_BUILTIN(__builtin_wasm_throw, "vIUiv*", "r", "exception-handling")
Expand Down
15 changes: 15 additions & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19851,6 +19851,21 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
Value *Size = EmitScalarExpr(E->getArg(1));
return Builder.CreateCall(Callee, {Ptr, Size});
}
case WebAssembly::BI__builtin_wasm_untag_ptr: {
llvm::Type *IntTy = llvm::Type::getInt64Ty(Builder.getContext());
Value *Ptr = EmitScalarExpr(E->getArg(0));
Value *IntPtr = Builder.CreateIntToPtr(Ptr, IntTy);
Value *BitMask = llvm::ConstantInt::get(IntTy, 0x0000'FFFF'FFFF'FFFF, false);
Value *StrippedPtr = Builder.CreateBinOp(llvm::Instruction::BinaryOps::And, IntPtr, BitMask);
return Builder.CreateIntToPtr(StrippedPtr, ConvertType(E->getType()));
}
case WebAssembly::BI__builtin_wasm_segment_set_tag: {
Value *Ptr = EmitScalarExpr(E->getArg(0));
Value *Tag = EmitScalarExpr(E->getArg(1));
Value *Size = EmitScalarExpr(E->getArg(2));
Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_segment_set_tag);
return Builder.CreateCall(Callee, {Ptr, Tag, Size});
}
case WebAssembly::BI__builtin_wasm_throw: {
Value *Tag = EmitScalarExpr(E->getArg(0));
Value *Obj = EmitScalarExpr(E->getArg(1));
Expand Down

0 comments on commit 0c6f055

Please sign in to comment.