Skip to content

[llvm][AArch64] Do not inline a function with different signing scheme. #80642

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 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 17 additions & 13 deletions llvm/include/llvm/IR/Attributes.td
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,25 @@ def UseSampleProfile : StrBoolAttr<"use-sample-profile">;
def DenormalFPMath : ComplexStrAttr<"denormal-fp-math", [FnAttr]>;
def DenormalFPMathF32 : ComplexStrAttr<"denormal-fp-math-f32", [FnAttr]>;

// Attiribute compatiblity rules are generated to check the attribute of the
// caller and callee and decide whether inlining should be allowed. CompatRule
// and child classes are used for the rule generation. CompatRule takes only a
// compare function which could be templated with the attribute type.
// CompatRuleStrAttr takes the compare function and the string for checking the
// string attributes.
class CompatRule<string F> {
// The name of the function called to check the attribute of the caller and
// callee and decide whether inlining should be allowed. The function's
// signature must match "bool(const Function&, const Function&)", where the
// first parameter is the reference to the caller and the second parameter is
// the reference to the callee. It must return false if the attributes of the
// caller and callee are incompatible, and true otherwise.
// The function's signature must match "bool(const Function&, const
// Function&)", where the first parameter is the reference to the caller and
// the second parameter is the reference to the callee. It must return false
// if the attributes of the caller and callee are incompatible, and true
// otherwise.
string CompatFunc = F;
string AttrName = "";
}

class CompatRuleAttr<string F, string Attr> : CompatRule<F> {
// The checker function is extended with an third argument as the function attribute string.
// bool(const Function&, const Function&, const StringRef&)"
class CompatRuleStrAttr<string F, string Attr> : CompatRule<F> {
// The checker function is extended with an third argument as the function
// attribute string "bool(const Function&, const Function&, const StringRef&)".
string AttrName = Attr;
}

Expand All @@ -366,10 +371,9 @@ def : CompatRule<"isEqual<ShadowCallStackAttr>">;
def : CompatRule<"isEqual<UseSampleProfileAttr>">;
def : CompatRule<"isEqual<NoProfileAttr>">;
def : CompatRule<"checkDenormMode">;
def : CompatRule<"checkStrictFP">;
def : CompatRuleAttr<"isEqual", "sign-return-address">;
def : CompatRuleAttr<"isEqual", "sign-return-address-key">;
def : CompatRuleAttr<"isEqual", "branch-protection-pauth-lr">;
def : CompatRuleStrAttr<"isEqual", "sign-return-address">;
def : CompatRuleStrAttr<"isEqual", "sign-return-address-key">;
def : CompatRuleStrAttr<"isEqual", "branch-protection-pauth-lr">;

class MergeRule<string F> {
// The name of the function called to merge the attributes of the caller and
Expand Down
7 changes: 0 additions & 7 deletions llvm/lib/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2039,13 +2039,6 @@ static bool checkDenormMode(const Function &Caller, const Function &Callee) {
return false;
}

static bool checkStrictFP(const Function &Caller, const Function &Callee) {
// Do not inline strictfp function into non-strictfp one. It would require
// conversion of all FP operations in host function to constrained intrinsics.
return !(Callee.getAttributes().hasFnAttr(Attribute::StrictFP) &&
!Caller.getAttributes().hasFnAttr(Attribute::StrictFP));
}

template<typename AttrClass>
static bool isEqual(const Function &Caller, const Function &Callee) {
return Caller.getFnAttribute(AttrClass::getKind()) ==
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,13 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
BasicBlock *OrigBB = CB.getParent();
Function *Caller = OrigBB->getParent();

// Do not inline strictfp function into non-strictfp one. It would require
// conversion of all FP operations in host function to constrained intrinsics.
if (CalledFunc->getAttributes().hasFnAttr(Attribute::StrictFP) &&
!Caller->getAttributes().hasFnAttr(Attribute::StrictFP)) {
return InlineResult::failure("incompatible strictfp attributes");
}

// GC poses two hazards to inlining, which only occur when the callee has GC:
// 1. If the caller has no GC, then the callee's GC must be propagated to the
// caller.
Expand Down
9 changes: 4 additions & 5 deletions llvm/utils/TableGen/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ void Attributes::emitFnAttrCompatCheck(raw_ostream &OS, bool IsStringAttr) {

for (auto *Rule : CompatRules) {
StringRef FuncName = Rule->getValueAsString("CompatFunc");
OS << " Ret &= " << FuncName << "(Caller, Callee";
StringRef AttrName = Rule->getValueAsString("AttrName");
if (AttrName.empty())
OS << " Ret &= " << FuncName << "(Caller, Callee);\n";
else
OS << " Ret &= " << FuncName << "(Caller, Callee, \"" << AttrName
<< "\");\n";
if (!AttrName.empty())
OS << ", \"" << AttrName << "\"";
OS << ");\n";
}

OS << "\n";
Expand Down