Skip to content

Commit 2bbbaac

Browse files
committed
Use a new Function::FunctionVisibility flag to cache the result
of isFullyInternal().
1 parent b47dac6 commit 2bbbaac

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

llvm/include/llvm/IR/Function.h

+7
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ class LLVM_ABI Function : public GlobalObject, public ilist_node<Function> {
115115
/// \ref BasicBlock.
116116
bool IsNewDbgInfoFormat;
117117

118+
/// If this function is known to be fully internal or not, this is set. A
119+
/// function with local linkage can still be passed as a pointer to an
120+
/// external routine, in which case it would be classified as External
121+
/// here.
122+
enum class FunctionVisibility { Unknown, FullyInternal, External };
123+
mutable FunctionVisibility FunVisibility;
124+
118125
/// hasLazyArguments/CheckLazyArguments - The argument list of a function is
119126
/// built on demand, so that the list isn't allocated until the first client
120127
/// needs it. The hasLazyArguments predicate returns true if the arg list

llvm/lib/IR/Function.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
492492
const Twine &name, Module *ParentModule)
493493
: GlobalObject(Ty, Value::FunctionVal, AllocMarker, Linkage, name,
494494
computeAddrSpace(AddrSpace, ParentModule)),
495-
NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
495+
NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(UseNewDbgInfoFormat),
496+
FunVisibility(FunctionVisibility::Unknown) {
496497
assert(FunctionType::isValidReturnType(getReturnType()) &&
497498
"invalid return type");
498499
setGlobalObjectSubClassData(0);

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -10200,10 +10200,7 @@ SDValue SystemZTargetLowering::lowerVECREDUCE_ADD(SDValue Op,
1020010200
DAG.getConstant(OpVT.getVectorNumElements() - 1, DL, MVT::i32));
1020110201
}
1020210202

10203-
// Only consider a function fully internal as long as it has local linkage
10204-
// and is not used in any other way than acting as the called function at
10205-
// call sites.
10206-
bool SystemZTargetLowering::isFullyInternal(const Function *Fn) const {
10203+
bool SystemZTargetLowering::isFullyInternal_impl(const Function *Fn) const {
1020710204
if (!Fn->hasLocalLinkage())
1020810205
return false;
1020910206
for (const User *U : Fn->users()) {
@@ -10216,6 +10213,17 @@ bool SystemZTargetLowering::isFullyInternal(const Function *Fn) const {
1021610213
return true;
1021710214
}
1021810215

10216+
// Only consider a function fully internal as long as it has local linkage
10217+
// and is not used in any other way than acting as the called function at
10218+
// call sites.
10219+
bool SystemZTargetLowering::isFullyInternal(const Function *Fn) const {
10220+
if (Fn->FunVisibility == Function::FunctionVisibility::Unknown)
10221+
Fn->FunVisibility = isFullyInternal_impl(Fn)
10222+
? Function::FunctionVisibility::FullyInternal
10223+
: Function::FunctionVisibility::External;
10224+
return Fn->FunVisibility == Function::FunctionVisibility::FullyInternal;
10225+
}
10226+
1021910227
static void printFunctionArgExts(const Function *F, raw_fd_ostream &OS) {
1022010228
FunctionType *FT = F->getFunctionType();
1022110229
const AttributeList &Attrs = F->getAttributes();

llvm/lib/Target/SystemZ/SystemZISelLowering.h

+1
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ class SystemZTargetLowering : public TargetLowering {
815815
getTargetMMOFlags(const Instruction &I) const override;
816816
const TargetRegisterClass *getRepRegClassFor(MVT VT) const override;
817817

818+
bool isFullyInternal_impl(const Function *Fn) const;
818819
bool isFullyInternal(const Function *Fn) const;
819820
void verifyNarrowIntegerArgs_Call(const SmallVectorImpl<ISD::OutputArg> &Outs,
820821
const Function *F, SDValue Callee) const;

0 commit comments

Comments
 (0)