Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,14 @@ class MapFactsToCallee : public FlowFunction<const llvm::Value *, Container> {
}
return {};
}
container_type Res;
// Pass global variables as is, if desired
// Globals could also be actual arguments, then the formal argument needs to
// be generated below.
// Need llvm::Constant here to cover also ConstantExpr and ConstantAggregate
if (PropagateGlobals && llvm::isa<llvm::Constant>(Source)) {
return {Source};
Res.insert(Source);
Comment thread
MMory marked this conversation as resolved.
}
container_type Res;
// Handle back propagation of return value in backwards analysis.
// We add it to the result here. Later, normal flow in callee can identify
// it
Expand Down Expand Up @@ -259,6 +261,7 @@ class MapFactsToCaller : public FlowFunction<const llvm::Value *, Container> {
const llvm::Function *CalleeFun;
const llvm::ReturnInst *ExitInst;
bool PropagateGlobals;
const bool PropagateZeroToCaller;
std::vector<const llvm::Value *> Actuals;
std::vector<const llvm::Value *> Formals;
std::function<bool(const llvm::Value *)> ParamPredicate;
Expand All @@ -271,10 +274,12 @@ class MapFactsToCaller : public FlowFunction<const llvm::Value *, Container> {
std::function<bool(const llvm::Value *)> ParamPredicate =
[](const llvm::Value *) { return true; },
std::function<bool(const llvm::Function *)> ReturnPredicate =
[](const llvm::Function *) { return true; })
[](const llvm::Function *) { return true; },
bool PropagateZeroToCaller = true)
Comment thread
MMory marked this conversation as resolved.
: CallSite(CallSite), CalleeFun(CalleeFun),
ExitInst(llvm::dyn_cast<llvm::ReturnInst>(ExitInst)),
PropagateGlobals(PropagateGlobals),
PropagateZeroToCaller(PropagateZeroToCaller),
ParamPredicate(std::move(ParamPredicate)),
ReturnPredicate(std::move(ReturnPredicate)) {
assert(ExitInst && "Should not be null");
Expand All @@ -294,12 +299,16 @@ class MapFactsToCaller : public FlowFunction<const llvm::Value *, Container> {
container_type computeTargets(const llvm::Value *Source) override {
assert(!CalleeFun->isDeclaration() &&
"Cannot perform mapping to caller for function declaration");
// Pass ZeroValue as is
// Pass ZeroValue as is, if desired
if (LLVMZeroValue::getInstance()->isLLVMZeroValue(Source)) {
return {Source};
if (PropagateZeroToCaller) {
Comment thread
vulder marked this conversation as resolved.
return {Source};
}
return {};
}
// Pass global variables as is, if desired
if (PropagateGlobals && llvm::isa<llvm::GlobalVariable>(Source)) {
// Need llvm::Constant here to cover also ConstantExpr and ConstantAggregate
if (PropagateGlobals && llvm::isa<llvm::Constant>(Source)) {
return {Source};
}
Comment thread
vulder marked this conversation as resolved.
// Do the parameter mapping
Expand Down Expand Up @@ -340,7 +349,8 @@ class MapFactsToCaller : public FlowFunction<const llvm::Value *, Container> {
}
}
// Collect return value facts
if (Source == ExitInst->getReturnValue() && ReturnPredicate(CalleeFun)) {
if (ExitInst != nullptr && Source == ExitInst->getReturnValue() &&
ReturnPredicate(CalleeFun)) {
Res.insert(CallSite);
}
return Res;
Expand Down