Skip to content

Commit e26af09

Browse files
authored
[llvm] Add BasicTTIImpl::areInlineCompatible for target feature subset checks (#117493)
This patch moves the `areInlineCompatible` implementation from multiple subclasses (`AArch64TTIImpl`, `RISCVTTIImpl`, `WebAssemblyTTIImpl`) to the base class `BasicTTIImpl`. The new implementation checks whether the callee's target features are a subset of the caller's, enabling consistent behavior across targets. Subclasses now simply delegate to the base implementation, reducing code duplication and improving maintainability.
1 parent 0bfc951 commit e26af09

File tree

6 files changed

+15
-48
lines changed

6 files changed

+15
-48
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,20 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
277277
E, AddressSpace, Alignment, MachineMemOperand::MONone, Fast);
278278
}
279279

280+
bool areInlineCompatible(const Function *Caller,
281+
const Function *Callee) const {
282+
const TargetMachine &TM = getTLI()->getTargetMachine();
283+
284+
const FeatureBitset &CallerBits =
285+
TM.getSubtargetImpl(*Caller)->getFeatureBits();
286+
const FeatureBitset &CalleeBits =
287+
TM.getSubtargetImpl(*Callee)->getFeatureBits();
288+
289+
// Inline a callee if its target-features are a subset of the callers
290+
// target-features.
291+
return (CallerBits & CalleeBits) == CalleeBits;
292+
}
293+
280294
bool hasBranchDivergence(const Function *F = nullptr) { return false; }
281295

282296
bool isSourceOfDivergence(const Value *V) { return false; }

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,7 @@ bool AArch64TTIImpl::areInlineCompatible(const Function *Caller,
266266
return false;
267267
}
268268

269-
const TargetMachine &TM = getTLI()->getTargetMachine();
270-
271-
const FeatureBitset &CallerBits =
272-
TM.getSubtargetImpl(*Caller)->getFeatureBits();
273-
const FeatureBitset &CalleeBits =
274-
TM.getSubtargetImpl(*Callee)->getFeatureBits();
275-
276-
// Inline a callee if its target-features are a subset of the callers
277-
// target-features.
278-
return (CallerBits & CalleeBits) == CalleeBits;
269+
return BaseT::areInlineCompatible(Caller, Callee);
279270
}
280271

281272
bool AArch64TTIImpl::areTypesABICompatible(

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,20 +2330,6 @@ bool RISCVTTIImpl::isLegalMaskedCompressStore(Type *DataTy, Align Alignment) {
23302330
return true;
23312331
}
23322332

2333-
bool RISCVTTIImpl::areInlineCompatible(const Function *Caller,
2334-
const Function *Callee) const {
2335-
const TargetMachine &TM = getTLI()->getTargetMachine();
2336-
2337-
const FeatureBitset &CallerBits =
2338-
TM.getSubtargetImpl(*Caller)->getFeatureBits();
2339-
const FeatureBitset &CalleeBits =
2340-
TM.getSubtargetImpl(*Callee)->getFeatureBits();
2341-
2342-
// Inline a callee if its target-features are a subset of the callers
2343-
// target-features.
2344-
return (CallerBits & CalleeBits) == CalleeBits;
2345-
}
2346-
23472333
/// See if \p I should be considered for address type promotion. We check if \p
23482334
/// I is a sext with right type and used in memory accesses. If it used in a
23492335
/// "complex" getelementptr, we allow it to be promoted without finding other

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

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

63-
bool areInlineCompatible(const Function *Caller,
64-
const Function *Callee) const;
65-
6663
/// Return the cost of materializing an immediate for a value operand of
6764
/// a store instruction.
6865
InstructionCost getStoreImmCost(Type *VecTy, TTI::OperandValueInfo OpInfo,

llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,6 @@ TTI::ReductionShuffle WebAssemblyTTIImpl::getPreferredExpandedReductionShuffle(
104104
return TTI::ReductionShuffle::SplitHalf;
105105
}
106106

107-
bool WebAssemblyTTIImpl::areInlineCompatible(const Function *Caller,
108-
const Function *Callee) const {
109-
// Allow inlining only when the Callee has a subset of the Caller's
110-
// features. In principle, we should be able to inline regardless of any
111-
// features because WebAssembly supports features at module granularity, not
112-
// function granularity, but without this restriction it would be possible for
113-
// a module to "forget" about features if all the functions that used them
114-
// were inlined.
115-
const TargetMachine &TM = getTLI()->getTargetMachine();
116-
117-
const FeatureBitset &CallerBits =
118-
TM.getSubtargetImpl(*Caller)->getFeatureBits();
119-
const FeatureBitset &CalleeBits =
120-
TM.getSubtargetImpl(*Callee)->getFeatureBits();
121-
122-
return (CallerBits & CalleeBits) == CalleeBits;
123-
}
124-
125107
void WebAssemblyTTIImpl::getUnrollingPreferences(
126108
Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP,
127109
OptimizationRemarkEmitter *ORE) const {

llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ class WebAssemblyTTIImpl final : public BasicTTIImplBase<WebAssemblyTTIImpl> {
7272
TTI::ReductionShuffle
7373
getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const;
7474

75-
bool areInlineCompatible(const Function *Caller,
76-
const Function *Callee) const;
77-
7875
bool supportsTailCalls() const;
7976

8077
bool isProfitableToSinkOperands(Instruction *I,

0 commit comments

Comments
 (0)