Skip to content

[PPC] Implement areInlineCompatible #126562

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

Merged
merged 4 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,20 @@ PPCTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
return BaseT::getIntrinsicInstrCost(ICA, CostKind);
}

bool PPCTTIImpl::areInlineCompatible(const Function *Caller,
const Function *Callee) const {
const TargetMachine &TM = getTLI()->getTargetMachine();

const FeatureBitset &CallerBits =
TM.getSubtargetImpl(*Caller)->getFeatureBits();
const FeatureBitset &CalleeBits =
TM.getSubtargetImpl(*Callee)->getFeatureBits();

// Check that targets features are exactly the same. We can revisit to see if
// we can improve this.
return CallerBits == CalleeBits;
}

bool PPCTTIImpl::areTypesABICompatible(const Function *Caller,
const Function *Callee,
const ArrayRef<Type *> &Types) const {
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class PPCTTIImpl : public BasicTTIImplBase<PPCTTIImpl> {
bool UseMaskForCond = false, bool UseMaskForGaps = false);
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
TTI::TargetCostKind CostKind);
bool areInlineCompatible(const Function *Caller,
const Function *Callee) const;
bool areTypesABICompatible(const Function *Caller, const Function *Callee,
const ArrayRef<Type *> &Types) const;
bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
Expand Down
63 changes: 63 additions & 0 deletions llvm/test/Transforms/Inline/PowerPC/inline-target-attr.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
; RUN: opt < %s -mtriple=powerpc64le-ibm-linux-gnu -S -passes=inline | FileCheck %s
; RUN: opt < %s -mtriple=powerpc64le-ibm-linux-gnu -S -passes='cgscc(inline)' | FileCheck %s

target datalayout = "E-m:e-i64:64-n32:64"
target triple = "powerpc64le-ibm-linux-gnu"

declare void @inlined()

define void @explicit() #0 {
; CHECK-LABEL: explicit
; CHECK: entry
; CHECK-NEXT: call void @not_compatible1()
; CHECK-NEXT: call void @inlined()
entry:
call void @not_compatible1()
call void @compatible1()
ret void
}

define void @not_compatible1() #1 {
entry:
call i32 @inlined()
ret void
}

define void @compatible1() #0 {
entry:
call void @inlined()
ret void
}

define void @default() #3 {
; CHECK-LABEL: default
; CHECK: entry
; CHECK-NEXT: call void @not_compatible2()
; CHECK-NEXT: call void @inlined()
entry:
call void @not_compatible2()
call void @compatible2()
ret void
}

define void @not_compatible2() #4 {
entry:
call void @inlined()
ret void
}

define void @compatible2() #5 {
entry:
call void @inlined()
ret void
}

; explicit
attributes #0 = { "target-cpu"="pwr7" "target-features"="+allow-unaligned-fp-access" }
attributes #1 = { "target-cpu"="pwr7" "target-features"="-allow-unaligned-fp-access" }

; pwr7 by default implies +vsx
attributes #3 = { "target-cpu"="pwr7" }
attributes #4 = { "target-cpu"="pwr7" "target-features"="-vsx" }
attributes #5 = { "target-cpu"="pwr7" "target-features"="+vsx" }