Skip to content

Commit 0ea815c

Browse files
committed
Apply review comments
1 parent 01c84ac commit 0ea815c

3 files changed

Lines changed: 54 additions & 63 deletions

File tree

lib/PhasarLLVM/ControlFlow/LLVMBasedCFG.cpp

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "phasar/Utils/Logger.h"
3737
#include "phasar/Utils/Utilities.h"
3838

39-
using namespace std;
4039
using namespace psr;
4140

4241
namespace psr {
@@ -46,14 +45,14 @@ LLVMBasedCFG::getFunctionOf(const llvm::Instruction *Inst) const {
4645
return Inst->getFunction();
4746
}
4847

49-
vector<const llvm::Instruction *>
48+
std::vector<const llvm::Instruction *>
5049
LLVMBasedCFG::getPredsOf(const llvm::Instruction *I) const {
5150
if (!IgnoreDbgInstructions) {
52-
if (auto *PrevInst = I->getPrevNode()) {
51+
if (const auto *PrevInst = I->getPrevNode()) {
5352
return {PrevInst};
5453
}
5554
} else {
56-
if (auto *PrevNonDbgInst =
55+
if (const auto *PrevNonDbgInst =
5756
I->getPrevNonDebugInstruction(false /*Only debug instructions*/)) {
5857
return {PrevNonDbgInst};
5958
}
@@ -77,54 +76,49 @@ LLVMBasedCFG::getPredsOf(const llvm::Instruction *I) const {
7776
return Preds;
7877
}
7978

80-
vector<const llvm::Instruction *>
79+
std::vector<const llvm::Instruction *>
8180
LLVMBasedCFG::getSuccsOf(const llvm::Instruction *I) const {
82-
vector<const llvm::Instruction *> Successors;
81+
8382
// case we wish to consider LLVM's debug instructions
8483
if (!IgnoreDbgInstructions) {
8584
if (const auto *NextInst = I->getNextNode()) {
86-
Successors.push_back(NextInst);
87-
}
88-
} else {
89-
if (const auto *NextNonDbgInst =
90-
I->getNextNonDebugInstruction(false /*Only debug instructions*/)) {
91-
Successors.push_back(NextNonDbgInst);
85+
return {NextInst};
9286
}
87+
} else if (const auto *NextNonDbgInst = I->getNextNonDebugInstruction(
88+
false /*Only debug instructions*/)) {
89+
return {NextNonDbgInst};
9390
}
9491

95-
if (Successors.empty()) {
96-
if (const auto *Branch = llvm::dyn_cast<llvm::BranchInst>(I);
97-
Branch && isStaticVariableLazyInitializationBranch(Branch)) {
98-
// Skip the "already initialized" case, such that the analysis is always
99-
// aware of the initialized value.
100-
const auto *NextInst = &Branch->getSuccessor(0)->front();
101-
if (IgnoreDbgInstructions &&
102-
llvm::isa<llvm::DbgInfoIntrinsic>(NextInst)) {
103-
NextInst = NextInst->getNextNonDebugInstruction(false);
104-
}
105-
Successors.push_back(NextInst);
106-
107-
} else {
108-
Successors.reserve(I->getNumSuccessors() + Successors.size());
109-
std::transform(llvm::succ_begin(I), llvm::succ_end(I),
110-
std::back_inserter(Successors),
111-
[](const llvm::BasicBlock *BB) {
112-
const llvm::Instruction *Succ = &BB->front();
113-
if (llvm::isa<llvm::DbgInfoIntrinsic>(Succ)) {
114-
Succ = Succ->getNextNonDebugInstruction(
115-
false /*Only debug instructions*/);
116-
}
117-
return Succ;
118-
});
92+
if (const auto *Branch = llvm::dyn_cast<llvm::BranchInst>(I);
93+
Branch && isStaticVariableLazyInitializationBranch(Branch)) {
94+
// Skip the "already initialized" case, such that the analysis is always
95+
// aware of the initialized value.
96+
const auto *NextInst = &Branch->getSuccessor(0)->front();
97+
if (IgnoreDbgInstructions && llvm::isa<llvm::DbgInfoIntrinsic>(NextInst)) {
98+
NextInst = NextInst->getNextNonDebugInstruction(false);
11999
}
100+
return {NextInst};
120101
}
121102

103+
std::vector<const llvm::Instruction *> Successors;
104+
Successors.reserve(I->getNumSuccessors() + Successors.size());
105+
std::transform(llvm::succ_begin(I), llvm::succ_end(I),
106+
std::back_inserter(Successors),
107+
[](const llvm::BasicBlock *BB) {
108+
const llvm::Instruction *Succ = &BB->front();
109+
if (llvm::isa<llvm::DbgInfoIntrinsic>(Succ)) {
110+
Succ = Succ->getNextNonDebugInstruction(
111+
false /*Only debug instructions*/);
112+
}
113+
return Succ;
114+
});
122115
return Successors;
123116
}
124117

125-
vector<pair<const llvm::Instruction *, const llvm::Instruction *>>
118+
std::vector<std::pair<const llvm::Instruction *, const llvm::Instruction *>>
126119
LLVMBasedCFG::getAllControlFlowEdges(const llvm::Function *Fun) const {
127-
vector<pair<const llvm::Instruction *, const llvm::Instruction *>> Edges;
120+
std::vector<std::pair<const llvm::Instruction *, const llvm::Instruction *>>
121+
Edges;
128122

129123
for (const auto &I : llvm::instructions(Fun)) {
130124
if (IgnoreDbgInstructions) {
@@ -148,9 +142,9 @@ LLVMBasedCFG::getAllControlFlowEdges(const llvm::Function *Fun) const {
148142
return Edges;
149143
}
150144

151-
vector<const llvm::Instruction *>
145+
std::vector<const llvm::Instruction *>
152146
LLVMBasedCFG::getAllInstructionsOf(const llvm::Function *Fun) const {
153-
vector<const llvm::Instruction *> Instructions;
147+
std::vector<const llvm::Instruction *> Instructions;
154148

155149
for (const auto &I : llvm::instructions(Fun)) {
156150
Instructions.push_back(&I);
@@ -165,41 +159,42 @@ LLVMBasedCFG::getStartPointsOf(const llvm::Function *Fun) const {
165159
return {};
166160
}
167161
if (!Fun->isDeclaration()) {
168-
auto *EntryInst = &Fun->front().front();
162+
const auto *EntryInst = &Fun->front().front();
169163
if (IgnoreDbgInstructions && llvm::isa<llvm::DbgInfoIntrinsic>(EntryInst)) {
170164
return {EntryInst->getNextNonDebugInstruction(
171165
false /*Only debug instructions*/)};
172166
}
173167
return {EntryInst};
174-
} else {
175-
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG)
176-
<< "Could not get starting points of '"
177-
<< Fun->getName().str() << "' because it is a declaration");
178-
return {};
179168
}
169+
170+
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG)
171+
<< "Could not get starting points of '" << Fun->getName().str()
172+
<< "' because it is a declaration");
173+
return {};
180174
}
181175

182176
std::set<const llvm::Instruction *>
183177
LLVMBasedCFG::getExitPointsOf(const llvm::Function *Fun) const {
184178
if (!Fun) {
185179
return {};
186180
}
181+
187182
if (!Fun->isDeclaration()) {
188183
// A function can have more than one exit point
189184
std::set<const llvm::Instruction *> ExitPoints;
190185
auto ExitPointVector = psr::getAllExitPoints(Fun);
191186

192-
for (auto *ExitPoint : ExitPointVector) {
187+
for (const auto *ExitPoint : ExitPointVector) {
193188
ExitPoints.insert(ExitPoint);
194189
}
195190

196191
return ExitPoints;
197-
} else {
198-
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG)
199-
<< "Could not get exit points of '" << Fun->getName().str()
200-
<< "' which is declaration!");
201-
return {};
202192
}
193+
194+
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG)
195+
<< "Could not get exit points of '" << Fun->getName().str()
196+
<< "' which is declaration!");
197+
return {};
203198
}
204199

205200
bool LLVMBasedCFG::isCallSite(const llvm::Instruction *Inst) const {
@@ -338,14 +333,14 @@ LLVMBasedCFG::getSpecialMemberFunctionType(const llvm::Function *Fun) const {
338333
return SpecialMemberFunctionType::None;
339334
}
340335

341-
string LLVMBasedCFG::getStatementId(const llvm::Instruction *Inst) const {
336+
std::string LLVMBasedCFG::getStatementId(const llvm::Instruction *Inst) const {
342337
return llvm::cast<llvm::MDString>(
343338
Inst->getMetadata(PhasarConfig::MetaDataKind())->getOperand(0))
344339
->getString()
345340
.str();
346341
}
347342

348-
string LLVMBasedCFG::getFunctionName(const llvm::Function *Fun) const {
343+
std::string LLVMBasedCFG::getFunctionName(const llvm::Function *Fun) const {
349344
return Fun->getName().str();
350345
}
351346

lib/PhasarLLVM/DataFlowSolver/IfdsIde/IFDSIDESolverConfig.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ using namespace psr;
1717

1818
namespace psr {
1919

20-
// IFDSIDESolverConfig::IFDSIDESolverConfig() {
21-
// setFlag(Options, SolverConfigOptions::EmitESG,
22-
// PhasarConfig::VariablesMap().count("emit-esg-as-dot"));
23-
// }
2420
IFDSIDESolverConfig::IFDSIDESolverConfig(SolverConfigOptions Options) noexcept
2521
: Options(Options) {}
2622

tools/phasar-llvm/phasar-llvm.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ int main(int Argc, const char **Argv) {
201201
("pointer-analysis,P", boost::program_options::value<std::string>()->notifier(&validateParamPointerAnalysis)->default_value("CFLAnders"), "Set the points-to analysis to be used (CFLSteens, CFLAnders). CFLSteens is ~O(N) but inaccurate while CFLAnders O(N^3) but more accurate.")
202202
("call-graph-analysis,C", boost::program_options::value<std::string>()->notifier(&validateParamCallGraphAnalysis)->default_value("OTF"), "Set the call-graph algorithm to be used (NORESOLVE, CHA, RTA, DTA, VTA, OTF)")
203203
("soundness", boost::program_options::value<std::string>()->notifier(&validateSoundnessFlag)->default_value("Soundy"), "Set the soundiness level to be used (Sound, Soundy, Unsound)")
204-
("auto-globals", boost::program_options::value<bool>()->default_value(true), "Enable automated global support (Default is true)")
204+
("auto-globals", boost::program_options::value<bool>()->default_value(true), "Enable automated global support")
205205
("classhierarchy-analysis,H", "Class-hierarchy analysis")
206206
("statistical-analysis,S", "Statistics")
207207
("mwa,M", "Enable Modulewise-program analysis mode")
@@ -226,10 +226,10 @@ int main(int Argc, const char **Argv) {
226226
("emit-pta-as-text", "Emit the points-to information as text")
227227
("emit-pta-as-dot", "Emit the points-to information as DOT graph")
228228
("emit-pta-as-json", "Emit the points-to information as JSON")
229-
("follow-return-past-seeds", boost::program_options::value<bool>()->default_value(false), "Let the IFDS/IDE Solver process unbalanced returns (Default is false)")
230-
("auto-add-zero", boost::program_options::value<bool>()->default_value(true), "Let the IFDS/IDE Solver automatically add the special zero value to any set of dataflow-facts (Default is true)")
231-
("compute-values", boost::program_options::value<bool>()->default_value(true), "Let the IDE Solver compute the values attached to each edge in the ESG (Default is true)")
232-
("record-edges", boost::program_options::value<bool>()->default_value(true), "Let the IFDS/IDE Solver record all ESG edges whole solving the dataflow problem (Default is true). This can have massive performance impact")
229+
("follow-return-past-seeds", boost::program_options::value<bool>()->default_value(false), "Let the IFDS/IDE Solver process unbalanced returns")
230+
("auto-add-zero", boost::program_options::value<bool>()->default_value(true), "Let the IFDS/IDE Solver automatically add the special zero value to any set of dataflow-facts")
231+
("compute-values", boost::program_options::value<bool>()->default_value(true), "Let the IDE Solver compute the values attached to each edge in the ESG")
232+
("record-edges", boost::program_options::value<bool>()->default_value(true), "Let the IFDS/IDE Solver record all ESG edges whole solving the dataflow problem. This can have massive performance impact")
233233
("persisted-summaries", boost::program_options::value<bool>()->default_value(false), "Let the IFDS/IDE Solver compute presisted procedure summaries (Currently not supported)")
234234
("pamm-out,A", boost::program_options::value<std::string>()->notifier(validateParamPammOutputFile)->default_value("PAMM_data.json"), "Filename for PAMM's gathered data")
235235

0 commit comments

Comments
 (0)