Skip to content

Commit 0ed11b0

Browse files
author
Yonghong Song
committed
[Transforms][IPO] Add remarks for ArgumentPromotion and DeadArgumentElimination
ArgumentPromotion and DeadArgumentElimination passes may change function signature. This makes bpf tracing difficult since users either not aware of signature change or need to poke into IR or assembly to understand the function signature change. This patch enabled to emit some remarks so if recompiling with -foptimization-record-file=<file>, users can check remarks to see what kind of signature changes for a particular function. The following are some examples for implemented remarks: Pass: deadargelim Name: ReturnValueRemoved DebugLoc: { File: 'bpf-next/net/mptcp/protocol.c', Line: 572, Column: 0 } Function: mptcp_check_data_fin Args: - String: 'removing return value ' - String: '0' Pass: deadargelim Name: ArgumentRemoved DebugLoc: { File: 'bpf-next/kernel/bpf/syscall.c', Line: 1670, Column: 0 } Function: map_delete_elem Args: - String: 'removing argument ' - String: '1' - String: ' (' - String: uattr.coerce0 - String: ')' Pass: argpromotion Name: ArgumentPromoted DebugLoc: { File: 'bpf-next/net/mptcp/protocol.h', Line: 570, Column: 0 } Function: mptcp_subflow_ctx Args: - String: 'promoting argument ' - String: '0' - String: ' (' - String: sk - String: ')' [1] #104678
1 parent df97673 commit 0ed11b0

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

llvm/lib/Transforms/IPO/ArgumentPromotion.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "llvm/Analysis/CallGraph.h"
4343
#include "llvm/Analysis/Loads.h"
4444
#include "llvm/Analysis/MemoryLocation.h"
45+
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
4546
#include "llvm/Analysis/TargetTransformInfo.h"
4647
#include "llvm/Analysis/ValueTracking.h"
4748
#include "llvm/IR/Argument.h"
@@ -126,6 +127,7 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
126127
// arguments.
127128
SmallVector<unsigned> NewArgIndices;
128129
AttributeList PAL = F->getAttributes();
130+
OptimizationRemarkEmitter ORE(F);
129131

130132
// First, determine the new argument list
131133
unsigned ArgNo = 0, NewArgNo = 0;
@@ -139,6 +141,12 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
139141
} else if (I->use_empty()) {
140142
// Dead argument (which are always marked as promotable)
141143
++NumArgumentsDead;
144+
ORE.emit([&]() {
145+
return OptimizationRemark(DEBUG_TYPE, "ArgumentRemoved", F)
146+
<< "removing argument " << std::to_string(ArgNo) << " ("
147+
<< I->getName() << ")";
148+
});
149+
142150
NewArgIndices.push_back((unsigned)-1);
143151
} else {
144152
const auto &ArgParts = ArgsToPromote.find(&*I)->second;
@@ -147,6 +155,12 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
147155
ArgAttrVec.push_back(AttributeSet());
148156
}
149157
++NumArgumentsPromoted;
158+
ORE.emit([&]() {
159+
return OptimizationRemark(DEBUG_TYPE, "ArgumentPromoted", F)
160+
<< "promoting argument " << std::to_string(ArgNo) << " ("
161+
<< I->getName() << ")";
162+
});
163+
150164
NewArgIndices.push_back((unsigned)-1);
151165
NewArgNo += ArgParts.size();
152166
}

llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/ADT/Statistic.h"
22+
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
2223
#include "llvm/IR/Argument.h"
2324
#include "llvm/IR/AttributeMask.h"
2425
#include "llvm/IR/Attributes.h"
@@ -748,6 +749,7 @@ bool DeadArgumentEliminationPass::removeDeadStuffFromFunction(Function *F) {
748749
// Set up to build a new list of parameter attributes.
749750
SmallVector<AttributeSet, 8> ArgAttrVec;
750751
const AttributeList &PAL = F->getAttributes();
752+
OptimizationRemarkEmitter ORE(F);
751753

752754
// Remember which arguments are still alive.
753755
SmallVector<bool, 10> ArgAlive(FTy->getNumParams(), false);
@@ -765,6 +767,12 @@ bool DeadArgumentEliminationPass::removeDeadStuffFromFunction(Function *F) {
765767
HasLiveReturnedArg |= PAL.hasParamAttr(ArgI, Attribute::Returned);
766768
} else {
767769
++NumArgumentsEliminated;
770+
771+
ORE.emit([&]() {
772+
return OptimizationRemark(DEBUG_TYPE, "ArgumentRemoved", F)
773+
<< "removing argument " << std::to_string(ArgI) << " ("
774+
<< I->getName() << ")";
775+
});
768776
LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - Removing argument "
769777
<< ArgI << " (" << I->getName() << ") from "
770778
<< F->getName() << "\n");
@@ -810,6 +818,11 @@ bool DeadArgumentEliminationPass::removeDeadStuffFromFunction(Function *F) {
810818
NewRetIdxs[Ri] = RetTypes.size() - 1;
811819
} else {
812820
++NumRetValsEliminated;
821+
822+
ORE.emit([&]() {
823+
return OptimizationRemark(DEBUG_TYPE, "ReturnValueRemoved", F)
824+
<< "removing return value " << std::to_string(Ri);
825+
});
813826
LLVM_DEBUG(
814827
dbgs() << "DeadArgumentEliminationPass - Removing return value "
815828
<< Ri << " from " << F->getName() << "\n");

0 commit comments

Comments
 (0)