Skip to content

Commit 05a7b22

Browse files
authored
[RISCV] Add areInlineCompatible for riscv target (#86639)
Inline a callee if its target-features are a subset of the callers target-features.
1 parent 16993c7 commit 05a7b22

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,3 +1676,17 @@ bool RISCVTTIImpl::isLegalMaskedCompressStore(Type *DataTy, Align Alignment) {
16761676
return false;
16771677
return true;
16781678
}
1679+
1680+
bool RISCVTTIImpl::areInlineCompatible(const Function *Caller,
1681+
const Function *Callee) const {
1682+
const TargetMachine &TM = getTLI()->getTargetMachine();
1683+
1684+
const FeatureBitset &CallerBits =
1685+
TM.getSubtargetImpl(*Caller)->getFeatureBits();
1686+
const FeatureBitset &CalleeBits =
1687+
TM.getSubtargetImpl(*Callee)->getFeatureBits();
1688+
1689+
// Inline a callee if its target-features are a subset of the callers
1690+
// target-features.
1691+
return (CallerBits & CalleeBits) == CalleeBits;
1692+
}

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
6060
: BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
6161
TLI(ST->getTargetLowering()) {}
6262

63+
bool areInlineCompatible(const Function *Caller,
64+
const Function *Callee) const;
65+
6366
/// Return the cost of materializing an immediate for a value operand of
6467
/// a store instruction.
6568
InstructionCost getStoreImmCost(Type *VecTy, TTI::OperandValueInfo OpInfo,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; RUN: opt < %s -mtriple=riscv64-unknown-linux-gnu -S -passes=inline | FileCheck %s
2+
; RUN: opt < %s -mtriple=riscv64-unknown-linux-gnu -S -passes='cgscc(inline)' | FileCheck %s
3+
; Check that we only inline when we have compatible target attributes.
4+
5+
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
6+
target triple = "riscv64-unknown-linux-gnu"
7+
8+
define i32 @foo() #0 {
9+
entry:
10+
%call = call i32 (...) @baz()
11+
ret i32 %call
12+
; CHECK-LABEL: foo
13+
; CHECK: call i32 (...) @baz()
14+
}
15+
declare i32 @baz(...) #0
16+
17+
define i32 @bar() #1 {
18+
entry:
19+
%call = call i32 @foo()
20+
ret i32 %call
21+
; CHECK-LABEL: bar
22+
; CHECK: call i32 (...) @baz()
23+
}
24+
25+
define i32 @qux() #0 {
26+
entry:
27+
%call = call i32 @bar()
28+
ret i32 %call
29+
; CHECK-LABEL: qux
30+
; CHECK: call i32 @bar()
31+
}
32+
33+
attributes #0 = { "target-cpu"="generic-rv64" "target-features"="+f,+d" }
34+
attributes #1 = { "target-cpu"="generic-rv64" "target-features"="+f,+d,+m,+v" }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not "RISCV" in config.root.targets:
2+
config.unsupported = True

0 commit comments

Comments
 (0)