Skip to content

Commit ce16be2

Browse files
author
sstefan1
committed
[Attributor][NFC] Make createShallowWrapper() available outside of Attributor
D85703 will need to create shallow wrappers in order to track the spmd icv. We need to make it available. Differential Revision: https://reviews.llvm.org/D89342
1 parent 27c691c commit ce16be2

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,22 @@ struct Attributor {
15351535
bool checkForAllReadWriteInstructions(function_ref<bool(Instruction &)> Pred,
15361536
AbstractAttribute &QueryingAA);
15371537

1538+
/// Create a shallow wrapper for \p F such that \p F has internal linkage
1539+
/// afterwards. It also sets the original \p F 's name to anonymous
1540+
///
1541+
/// A wrapper is a function with the same type (and attributes) as \p F
1542+
/// that will only call \p F and return the result, if any.
1543+
///
1544+
/// Assuming the declaration of looks like:
1545+
/// rty F(aty0 arg0, ..., atyN argN);
1546+
///
1547+
/// The wrapper will then look as follows:
1548+
/// rty wrapper(aty0 arg0, ..., atyN argN) {
1549+
/// return F(arg0, ..., argN);
1550+
/// }
1551+
///
1552+
static void createShallowWrapper(Function &F);
1553+
15381554
/// Return the data layout associated with the anchor scope.
15391555
const DataLayout &getDataLayout() const { return InfoCache.DL; }
15401556

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ STATISTIC(NumFnWithExactDefinition,
5151
"Number of functions with exact definitions");
5252
STATISTIC(NumFnWithoutExactDefinition,
5353
"Number of functions without exact definitions");
54-
STATISTIC(NumFnShallowWrapperCreated, "Number of shallow wrappers created");
54+
STATISTIC(NumFnShallowWrappersCreated, "Number of shallow wrappers created");
5555
STATISTIC(NumAttributesTimedOut,
5656
"Number of abstract attributes timed out before fixpoint");
5757
STATISTIC(NumAttributesValidFixpoint,
@@ -1415,23 +1415,7 @@ ChangeStatus Attributor::updateAA(AbstractAttribute &AA) {
14151415
return CS;
14161416
}
14171417

1418-
/// Create a shallow wrapper for \p F such that \p F has internal linkage
1419-
/// afterwards. It also sets the original \p F 's name to anonymous
1420-
///
1421-
/// A wrapper is a function with the same type (and attributes) as \p F
1422-
/// that will only call \p F and return the result, if any.
1423-
///
1424-
/// Assuming the declaration of looks like:
1425-
/// rty F(aty0 arg0, ..., atyN argN);
1426-
///
1427-
/// The wrapper will then look as follows:
1428-
/// rty wrapper(aty0 arg0, ..., atyN argN) {
1429-
/// return F(arg0, ..., argN);
1430-
/// }
1431-
///
1432-
static void createShallowWrapper(Function &F) {
1433-
assert(AllowShallowWrappers &&
1434-
"Cannot create a wrapper if it is not allowed!");
1418+
void Attributor::createShallowWrapper(Function &F) {
14351419
assert(!F.isDeclaration() && "Cannot create a wrapper around a declaration!");
14361420

14371421
Module &M = *F.getParent();
@@ -1475,7 +1459,7 @@ static void createShallowWrapper(Function &F) {
14751459
CI->addAttribute(AttributeList::FunctionIndex, Attribute::NoInline);
14761460
ReturnInst::Create(Ctx, CI->getType()->isVoidTy() ? nullptr : CI, EntryBB);
14771461

1478-
NumFnShallowWrapperCreated++;
1462+
NumFnShallowWrappersCreated++;
14791463
}
14801464

14811465
/// Make another copy of the function \p F such that the copied version has
@@ -2279,7 +2263,7 @@ static bool runAttributorOnFunctions(InformationCache &InfoCache,
22792263
if (AllowShallowWrappers)
22802264
for (Function *F : Functions)
22812265
if (!A.isFunctionIPOAmendable(*F))
2282-
createShallowWrapper(*F);
2266+
Attributor::createShallowWrapper(*F);
22832267

22842268
// Internalize non-exact functions
22852269
// TODO: for now we eagerly internalize functions without calculating the

0 commit comments

Comments
 (0)