Skip to content

Commit 29b1a4f

Browse files
committed
inliner behavior per msvc
1 parent 1072196 commit 29b1a4f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

llvm/include/llvm/IR/Attributes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ def : CompatRule<"isEqual<UseSampleProfileAttr>">;
442442
def : CompatRule<"isEqual<NoProfileAttr>">;
443443
def : CompatRule<"checkDenormMode">;
444444
def : CompatRule<"checkStrictFP">;
445+
def : CompatRule<"checkSections">;
445446
def : CompatRuleStrAttr<"isEqual", "sign-return-address">;
446447
def : CompatRuleStrAttr<"isEqual", "sign-return-address-key">;
447448
def : CompatRuleStrAttr<"isEqual", "branch-protection-pauth-lr">;

llvm/lib/IR/Attributes.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,44 @@ static bool checkStrictFP(const Function &Caller, const Function &Callee) {
25072507
Caller.getAttributes().hasFnAttr(Attribute::StrictFP);
25082508
}
25092509

2510+
static bool checkSections(const Function &Caller, const Function &Callee) {
2511+
// Implement MSVC compatible cross-section inlining rules
2512+
StringRef CallerSection = Caller.getSection();
2513+
StringRef CalleeSection = Callee.getSection();
2514+
2515+
// sections match, inline ok
2516+
if (!CallerSection.compare(CalleeSection))
2517+
return true;
2518+
2519+
bool isCallerPaged = CallerSection.starts_with("PAGE");
2520+
bool isCalleePaged = CalleeSection.starts_with("PAGE");
2521+
2522+
// Prevent inlining of non-paged code into a paged caller
2523+
// Prevent inlining of paged code into non-paged caller
2524+
// Section names are compared only before the '$' separator if present
2525+
2526+
if (isCallerPaged) {
2527+
size_t CallerComparable = CallerSection.size();
2528+
size_t CalleeComparable = CalleeSection.size();
2529+
size_t CallerSep = CallerSection.find('$');
2530+
size_t CalleeSep = CalleeSection.find('$');
2531+
2532+
if (CallerSep != StringRef::npos)
2533+
CallerComparable = CallerSep;
2534+
if (CalleeSep != StringRef::npos)
2535+
CalleeComparable = CalleeSep;
2536+
if (CallerComparable != CalleeComparable)
2537+
return false;
2538+
2539+
StringRef CallerComparableSection = CallerSection.substr(0, CallerComparable);
2540+
StringRef CalleeComparableSection = CalleeSection.substr(0, CallerComparable);
2541+
return !CallerComparableSection.compare(CalleeComparableSection);
2542+
} else if (isCalleePaged)
2543+
return false;
2544+
2545+
return true;
2546+
}
2547+
25102548
template<typename AttrClass>
25112549
static bool isEqual(const Function &Caller, const Function &Callee) {
25122550
return Caller.getFnAttribute(AttrClass::getKind()) ==

0 commit comments

Comments
 (0)