forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BPF: Implement TTI.IntImmCost() properly
This patch implemented TTI.IntImmCost() properly. Each BPF insn has 32bit immediate space, so for any immediate which can be represented as 32bit signed int, the cost is technically free. If an int cannot be presented as a 32bit signed int, a ld_imm64 instruction is needed and a TCC_Basic is returned. This change is motivated when we observed that several bpf selftests failed with latest llvm trunk, e.g., #10/16 strobemeta.o:FAIL #10/17 strobemeta_nounroll1.o:FAIL #10/18 strobemeta_nounroll2.o:FAIL #10/19 strobemeta_subprogs.o:FAIL #96 snprintf_btf:FAIL The reason of the failure is due to that SpeculateAroundPHIsPass did aggressive transformation which alters control flow for which currently verifer cannot handle well. In llvm12, SpeculateAroundPHIsPass is not called. SpeculateAroundPHIsPass relied on TTI.getIntImmCost() and TTI.getIntImmCostInst() for profitability analysis. This patch implemented TTI.getIntImmCost() properly for BPF backend which also prevented transformation which caused the above test failures. Differential Revision: https://reviews.llvm.org/D96448
- Loading branch information
1 parent
7e3b9ab
commit a260ae7
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//===------ BPFTargetTransformInfo.h - BPF specific TTI ---------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file uses the target's specific information to | ||
// provide more precise answers to certain TTI queries, while letting the | ||
// target independent and default TTI implementations handle the rest. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H | ||
#define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H | ||
|
||
#include "BPFTargetMachine.h" | ||
#include "llvm/Analysis/TargetTransformInfo.h" | ||
#include "llvm/CodeGen/BasicTTIImpl.h" | ||
|
||
namespace llvm { | ||
class BPFTTIImpl : public BasicTTIImplBase<BPFTTIImpl> { | ||
typedef BasicTTIImplBase<BPFTTIImpl> BaseT; | ||
typedef TargetTransformInfo TTI; | ||
friend BaseT; | ||
|
||
const BPFSubtarget *ST; | ||
const BPFTargetLowering *TLI; | ||
|
||
const BPFSubtarget *getST() const { return ST; } | ||
const BPFTargetLowering *getTLI() const { return TLI; } | ||
|
||
public: | ||
explicit BPFTTIImpl(const BPFTargetMachine *TM, const Function &F) | ||
: BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), | ||
TLI(ST->getTargetLowering()) {} | ||
|
||
int getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) { | ||
if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue())) | ||
return TTI::TCC_Free; | ||
|
||
return TTI::TCC_Basic; | ||
} | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H |