|
43 | 43 | #include "llvm/CodeGen/BasicTTIImpl.h"
|
44 | 44 | #include "llvm/CodeGen/CostTable.h"
|
45 | 45 | #include "llvm/CodeGen/TargetLowering.h"
|
| 46 | +#include "llvm/IR/InstIterator.h" |
46 | 47 | #include "llvm/IR/IntrinsicInst.h"
|
47 | 48 | #include "llvm/Support/Debug.h"
|
48 | 49 |
|
@@ -5187,9 +5188,48 @@ bool X86TTIImpl::areInlineCompatible(const Function *Caller,
|
5187 | 5188 | const FeatureBitset &CalleeBits =
|
5188 | 5189 | TM.getSubtargetImpl(*Callee)->getFeatureBits();
|
5189 | 5190 |
|
| 5191 | + // Check whether features are the same (apart from the ignore list). |
5190 | 5192 | FeatureBitset RealCallerBits = CallerBits & ~InlineFeatureIgnoreList;
|
5191 | 5193 | FeatureBitset RealCalleeBits = CalleeBits & ~InlineFeatureIgnoreList;
|
5192 |
| - return (RealCallerBits & RealCalleeBits) == RealCalleeBits; |
| 5194 | + if (RealCallerBits == RealCalleeBits) |
| 5195 | + return true; |
| 5196 | + |
| 5197 | + // If the features are a subset, we need to additionally check for calls |
| 5198 | + // that may become ABI-incompatible as a result of inlining. |
| 5199 | + if ((RealCallerBits & RealCalleeBits) != RealCalleeBits) |
| 5200 | + return false; |
| 5201 | + |
| 5202 | + for (const Instruction &I : instructions(Callee)) { |
| 5203 | + if (const auto *CB = dyn_cast<CallBase>(&I)) { |
| 5204 | + SmallVector<Type *, 8> Types; |
| 5205 | + for (Value *Arg : CB->args()) |
| 5206 | + Types.push_back(Arg->getType()); |
| 5207 | + if (!CB->getType()->isVoidTy()) |
| 5208 | + Types.push_back(CB->getType()); |
| 5209 | + |
| 5210 | + // Simple types are always ABI compatible. |
| 5211 | + auto IsSimpleTy = [](Type *Ty) { |
| 5212 | + return !Ty->isVectorTy() && !Ty->isAggregateType(); |
| 5213 | + }; |
| 5214 | + if (all_of(Types, IsSimpleTy)) |
| 5215 | + continue; |
| 5216 | + |
| 5217 | + if (Function *NestedCallee = CB->getCalledFunction()) { |
| 5218 | + // Assume that intrinsics are always ABI compatible. |
| 5219 | + if (NestedCallee->isIntrinsic()) |
| 5220 | + continue; |
| 5221 | + |
| 5222 | + // Do a precise compatibility check. |
| 5223 | + if (!areTypesABICompatible(Caller, NestedCallee, Types)) |
| 5224 | + return false; |
| 5225 | + } else { |
| 5226 | + // We don't know the target features of the callee, |
| 5227 | + // assume it is incompatible. |
| 5228 | + return false; |
| 5229 | + } |
| 5230 | + } |
| 5231 | + } |
| 5232 | + return true; |
5193 | 5233 | }
|
5194 | 5234 |
|
5195 | 5235 | bool X86TTIImpl::areTypesABICompatible(const Function *Caller,
|
|
0 commit comments