-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[BPF] Allow libcalls behind a feature gate #168442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,6 +208,7 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM, | |
| HasMovsx = STI.hasMovsx(); | ||
|
|
||
| AllowsMisalignedMemAccess = STI.getAllowsMisalignedMemAccess(); | ||
| AllowBuiltinCalls = STI.getAllowBuiltinCalls(); | ||
| } | ||
|
|
||
| bool BPFTargetLowering::allowsMisalignedMemoryAccesses(EVT VT, unsigned, Align, | ||
|
|
@@ -567,9 +568,10 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, | |
| } else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee)) { | ||
| if (StringRef(E->getSymbol()) != BPF_TRAP) { | ||
| Callee = DAG.getTargetExternalSymbol(E->getSymbol(), PtrVT, 0); | ||
| fail(CLI.DL, DAG, | ||
| Twine("A call to built-in function '" + StringRef(E->getSymbol()) + | ||
| "' is not supported.")); | ||
| if (!AllowBuiltinCalls) | ||
| fail(CLI.DL, DAG, | ||
| Twine("A call to built-in function '" + StringRef(E->getSymbol()) + | ||
| "' is not supported.")); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1196,3 +1198,18 @@ bool BPFTargetLowering::isLegalAddressingMode(const DataLayout &DL, | |
|
|
||
| return true; | ||
| } | ||
|
|
||
| bool BPFTargetLowering::shouldSignExtendTypeInLibCall(Type *Ty, | ||
| bool IsSigned) const { | ||
| return IsSigned || Ty->isIntegerTy(32); | ||
| } | ||
|
|
||
| bool BPFTargetLowering::CanLowerReturn( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a separate change |
||
| CallingConv::ID CallConv, MachineFunction &MF, bool IsVarArg, | ||
| const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context, | ||
| const Type *RetTy) const { | ||
| // At minimal return Outs.size() <= 1, or check valid types in CC. | ||
| SmallVector<CCValAssign, 16> RVLocs; | ||
| CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context); | ||
| return CCInfo.CheckReturn(Outs, getHasAlu32() ? RetCC_BPF32 : RetCC_BPF64); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. End of file whitespace error |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| ; RUN: llc -march=bpfel -mattr=+allow-builtin-calls < %s | FileCheck %s | ||
| ; | ||
| ; C code for this test case: | ||
| ; | ||
| ; long func(long a, long b) { | ||
| ; long x; | ||
| ; return __builtin_mul_overflow(a, b, &x); | ||
| ; } | ||
|
|
||
|
|
||
| declare { i64, i1 } @llvm.smul.with.overflow.i64(i64, i64) | ||
|
|
||
| define noundef range(i64 0, 2) i64 @func(i64 noundef %a, i64 noundef %b) local_unnamed_addr { | ||
| entry: | ||
| %0 = tail call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %a, i64 %b) | ||
| %1 = extractvalue { i64, i1 } %0, 1 | ||
| %conv = zext i1 %1 to i64 | ||
| ret i64 %conv | ||
| } | ||
|
|
||
| ; CHECK-LABEL: func | ||
| ; CHECK: r4 = r2 | ||
| ; CHECK: r2 = r1 | ||
| ; CHECK: r3 = r2 | ||
| ; CHECK: r3 s>>= 63 | ||
| ; CHECK: r5 = r4 | ||
| ; CHECK: r5 s>>= 63 | ||
| ; CHECK: r1 = r10 | ||
| ; CHECK: r1 += -16 | ||
| ; CHECK: call __multi3 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain in the commit/description message how do you handle __multi3 function? This is clang built-in so you will implement this function in the bpf prog?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we build the core library in Rust, which implements the primitive types and their math operations, we also build as a dependency Rust's compiler-builtin crate. This crate has the implementation of Once we build the target program and all the dependencies (core and compiler-builtins), we merge all LLVM modules and emit a final object.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this message clear for the commit?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the commit message. Let me know if it is clear. I'm happy to re-write it. |
||
| ; CHECK: r1 = *(u64 *)(r10 - 16) | ||
| ; CHECK: r1 s>>= 63 | ||
| ; CHECK: w0 = 1 | ||
| ; CHECK: r2 = *(u64 *)(r10 - 8) | ||
| ; CHECK: if r2 != r1 goto LBB0_2 | ||
| ; CHECK: # %bb.1: # %entry | ||
| ; CHECK: w0 = 0 | ||
| ; CHECK: LBB0_2: # %entry | ||
| ; CHECK: exit | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a separate change