Skip to content

Commit c0e70d7

Browse files
committed
[LoongArch] Add areInlineCompatible
Inline a callee if its target-features are a subset of the callers target-features.
1 parent 56c091e commit c0e70d7

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

llvm/lib/Target/LoongArch/LoongArchTargetTransformInfo.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ using namespace llvm;
1919

2020
#define DEBUG_TYPE "loongarchtti"
2121

22+
bool LoongArchTTIImpl::areInlineCompatible(const Function *Caller,
23+
const Function *Callee) const {
24+
const TargetMachine &TM = getTLI()->getTargetMachine();
25+
26+
const FeatureBitset &CallerBits =
27+
TM.getSubtargetImpl(*Caller)->getFeatureBits();
28+
const FeatureBitset &CalleeBits =
29+
TM.getSubtargetImpl(*Callee)->getFeatureBits();
30+
31+
// Inline a callee if its target-features are a subset of the callers
32+
// target-features.
33+
return (CallerBits & CalleeBits) == CalleeBits;
34+
}
35+
2236
TypeSize LoongArchTTIImpl::getRegisterBitWidth(
2337
TargetTransformInfo::RegisterKind K) const {
2438
TypeSize DefSize = TargetTransformInfoImplBase::getRegisterBitWidth(K);

llvm/lib/Target/LoongArch/LoongArchTargetTransformInfo.h

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class LoongArchTTIImpl : public BasicTTIImplBase<LoongArchTTIImpl> {
4040
: BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
4141
TLI(ST->getTargetLowering()) {}
4242

43+
bool areInlineCompatible(const Function *Caller,
44+
const Function *Callee) const;
45+
4346
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const;
4447
unsigned getNumberOfRegisters(unsigned ClassID) const;
4548
unsigned getRegisterClassForType(bool Vector, Type *Ty = nullptr) const;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; RUN: opt < %s -mtriple=loongarch64-unknown-linux-gnu -S -passes=inline | FileCheck %s
2+
; RUN: opt < %s -mtriple=loongarch64-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-n32:64-S128"
6+
target triple = "loongarch64-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-la64" "target-features"="+f,+d" }
34+
attributes #1 = { "target-cpu"="generic-la64" "target-features"="+f,+d,+lsx,+lasx" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not "LoongArch" in config.root.targets:
2+
config.unsupported = True

0 commit comments

Comments
 (0)