Skip to content

Commit

Permalink
refactor addConstantVal/ObjNode
Browse files Browse the repository at this point in the history
  • Loading branch information
bjjwwang committed Dec 10, 2024
1 parent 60f9386 commit 5d9d52b
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 74 deletions.
69 changes: 61 additions & 8 deletions svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void SVFIRBuilder::initialiseNodes()
if(iter->second == symTable->blkPtrSymID())
continue;
if (iter->second == symTable->nullPtrSymID()) {
pag->addConstantValNode(iter->first, iter->second, nullptr);
pag->addConstantNullPtrValNode(iter->first, iter->second, nullptr);
}

const ICFGNode* icfgNode = nullptr;
Expand All @@ -240,6 +240,31 @@ void SVFIRBuilder::initialiseNodes()
const CallGraphNode* cgn = llvmModuleSet()->getCallGraphNode(func);
pag->addFunValNode(cgn, iter->second, icfgNode);
}
else if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addConstantFPValNode(iter->first, fpValue->getValueAPF().convertToDouble(), iter->second, icfgNode);
llvmModuleSet()->setValueAttr(fpValue, pag->getGNode(iter->second));
}
else if (auto intValue = SVFUtil::dyn_cast<ConstantInt>(llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addConstantFPValNode(iter->first, intValue->getSExtValue(), intValue->getZExtValue(), iter->second, icfgNode);
llvmModuleSet()->setValueAttr(intValue, pag->getGNode(iter->second));
}
else if (auto nullValue = SVFUtil::dyn_cast<ConstantPointerNull>(llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addConstantNullPtrValNode(iter->first, iter->second, icfgNode);
llvmModuleSet()->setValueAttr(nullValue, pag->getGNode(iter->second));
}
else if (auto globalValue = SVFUtil::dyn_cast<GlobalVariable>(llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addGlobalValueValNode(iter->first, iter->second, icfgNode);
llvmModuleSet()->setValueAttr(globalValue, pag->getGNode(iter->second));
}
else if (auto dataValue = SVFUtil::dyn_cast<ConstantData>(llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addGlobalValueValNode(iter->first, iter->second, icfgNode);
llvmModuleSet()->setValueAttr(dataValue, pag->getGNode(iter->second));
}
else if (auto llvmValue = SVFUtil::dyn_cast<Constant>(llvmModuleSet()->getLLVMValue(iter->first))) {
pag->addConstantValNode(iter->first, iter->second, icfgNode);
llvmModuleSet()->setValueAttr(llvmValue, pag->getGNode(iter->second));
Expand All @@ -257,18 +282,46 @@ void SVFIRBuilder::initialiseNodes()
DBOUT(DPAGBuild, outs() << "add obj node " << iter->second << "\n");
if(iter->second == symTable->blackholeSymID() || iter->second == symTable->constantSymID())
continue;

if (const Function* func = SVFUtil::dyn_cast<Function>(
llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addFunObjNode(llvmModuleSet()->getCallGraphNode(func), iter->second);
}
else if (auto llvmValue = SVFUtil::dyn_cast<Constant>(llvmModuleSet()->getLLVMValue(iter->first))) {
pag->addConstantObjNode(iter->first, iter->second);
llvmModuleSet()->setValueAttr(llvmValue, pag->getGNode(iter->second));
}
else
{
pag->addObjNode(iter->first, iter->second);
else {
if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addConstantFPObjNode(iter->first, fpValue->getValueAPF().convertToDouble(), iter->second);
llvmModuleSet()->setValueAttr(fpValue, pag->getGNode(iter->second));
}
else if (auto intValue = SVFUtil::dyn_cast<ConstantInt>(llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addConstantFPObjNode(iter->first, intValue->getSExtValue(), intValue->getZExtValue(), iter->second);
llvmModuleSet()->setValueAttr(intValue, pag->getGNode(iter->second));
}
else if (auto nullValue = SVFUtil::dyn_cast<ConstantPointerNull>(llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addConstantNullPtrObjNode(iter->first, iter->second);
llvmModuleSet()->setValueAttr(nullValue, pag->getGNode(iter->second));
}
else if (auto globalValue = SVFUtil::dyn_cast<GlobalVariable>(llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addGlobalValueObjNode(iter->first, iter->second);
llvmModuleSet()->setValueAttr(globalValue, pag->getGNode(iter->second));
}
else if (auto dataValue = SVFUtil::dyn_cast<ConstantData>(llvmModuleSet()->getLLVMValue(iter->first)))
{
pag->addGlobalValueObjNode(iter->first, iter->second);
llvmModuleSet()->setValueAttr(dataValue, pag->getGNode(iter->second));
}
else if (auto llvmValue = SVFUtil::dyn_cast<Constant>(llvmModuleSet()->getLLVMValue(iter->first))) {
pag->addConstantObjNode(iter->first, iter->second);
llvmModuleSet()->setValueAttr(llvmValue, pag->getGNode(iter->second));
}
else
{
pag->addObjNode(iter->first, iter->second);
}
}
}

Expand Down
136 changes: 70 additions & 66 deletions svf/include/SVFIR/SVFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,84 +579,88 @@ class SVFIR : public IRGraph
return addNode(node,i);
}

inline NodeID addConstantFPValNode(const SVFValue* curInst, double dval, const NodeID i,
const ICFGNode* icfgNode)
{
SVFVar* node = new ConstantFPValVar(curInst, dval, i, icfgNode);
return addNode(node, i);
}

inline NodeID addConstantValNode(const SVFValue* curInst, const NodeID i, const ICFGNode* icfgNode) {
if (const SVFConstantFP* constFp = SVFUtil::dyn_cast<SVFConstantFP>(curInst))
{
SVFVar* node = new ConstantFPValVar(curInst, constFp->getFPValue(), i, icfgNode);
return addNode(node,i);
}
// ConstantInt
else if (const SVFConstantInt* constInt = SVFUtil::dyn_cast<SVFConstantInt>(curInst))
{
SVFVar* node = new ConstantIntValVar(curInst, constInt->getSExtValue(), constInt->getZExtValue(), i, icfgNode);
return addNode(node,i);
}
// constNullptr
else if (SVFUtil::isa<SVFConstantNullPtr>(curInst)) {
SVFVar* node = new ConstantNullPtrValVar(curInst, i, icfgNode);
return addNode(node,i);
}
inline NodeID addConstantIntValNode(const SVFValue* curInst, s64_t sval, u64_t zval, const NodeID i,
const ICFGNode* icfgNode)
{
SVFVar* node = new ConstantIntValVar(curInst, sval, zval, i, icfgNode);
return addNode(node, i);
}

else if (SVFUtil::isa<SVFGlobalValue>(curInst))
{
SVFVar* node = new GlobalValueValvar(curInst, i, icfgNode);
return addNode(node,i);
}
inline NodeID addConstantNullPtrValNode(const SVFValue* curInst, const NodeID i, const ICFGNode* icfgNode)
{
SVFVar* node = new ConstantNullPtrValVar(curInst, i, icfgNode);
return addNode(node, i);
}

else if (SVFUtil::isa<SVFConstantData>(curInst)) {
SVFVar* node = new ConstantDataValVar(curInst, i, icfgNode);
return addNode(node,i);
}
inline NodeID addGlobalValueValNode(const SVFValue* curInst, const NodeID i, const ICFGNode* icfgNode)
{
SVFVar* node = new GlobalValueValvar(curInst, i, icfgNode);
return addNode(node, i);
}

else if (SVFUtil::isa<SVFConstant>(curInst))
{
SVFVar* node = new ConstantValVar(curInst,i, icfgNode);
return addNode(node, i);
}
assert(false && "not a constant value?");
inline NodeID addConstantDataValNode(const SVFValue* curInst, const NodeID i, const ICFGNode* icfgNode)
{
SVFVar* node = new ConstantDataValVar(curInst, i, icfgNode);
return addNode(node, i);
}

inline NodeID addConstantObjNode(const SVFValue* curInst, const NodeID i) {
inline NodeID addConstantValNode(const SVFValue* curInst, const NodeID i, const ICFGNode* icfgNode)
{
SVFVar* node = new ConstantValVar(curInst, i, icfgNode);
return addNode(node, i);
}

inline NodeID addConstantFPObjNode(const SVFValue* curInst, double dval, const NodeID i)
{
const MemObj* mem = getMemObj(curInst);
NodeID base = mem->getId();
memToFieldsMap[base].set(mem->getId());
if (const SVFConstantFP* constFp = SVFUtil::dyn_cast<SVFConstantFP>(curInst))
{
ConstantFPObjVar* node = new ConstantFPObjVar(curInst, constFp->getFPValue(), mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}
// ConstantInt
else if (const SVFConstantInt* constInt = SVFUtil::dyn_cast<SVFConstantInt>(curInst))
{
ConstantIntObjVar* node = new ConstantIntObjVar(curInst, constInt->getSExtValue(), constInt->getZExtValue(), mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}
// constNullptr
else if (SVFUtil::isa<SVFConstantNullPtr>(curInst)) {
SVFVar* node = new ConstantNullPtrObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}
ConstantFPObjVar* node = new ConstantFPObjVar(curInst, dval, mem->getId(), mem);
return addObjNode(curInst, node, mem->getId());
}

else if (SVFUtil::isa<SVFGlobalValue>(curInst))
{
GlobalValueObjVar* node = new GlobalValueObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}

else if (SVFUtil::isa<SVFConstantData>(curInst)) {
ConstantDataObjVar* node = new ConstantDataObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}
inline NodeID addConstantIntObjNode(const SVFValue* curInst, s64_t sval, u64_t zval, const NodeID i) {
const MemObj* mem = getMemObj(curInst);
ConstantIntObjVar* node =
new ConstantIntObjVar(curInst, sval, zval, mem->getId(), mem);
return addObjNode(curInst, node, mem->getId());
}

else if (SVFUtil::isa<SVFConstant>(curInst))
{
ConstantObjVar* node = new ConstantObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}
assert(false && "not a constant value?");

inline NodeID addConstantNullPtrObjNode(const SVFValue* curInst, const NodeID i) {
const MemObj* mem = getMemObj(curInst);
ConstantNullPtrObjVar* node = new ConstantNullPtrObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}

inline NodeID addGlobalValueObjNode(const SVFValue* curInst, const NodeID i)
{
const MemObj* mem = getMemObj(curInst);
GlobalValueObjVar* node = new GlobalValueObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}

inline NodeID addConstantDataObjNode(const SVFValue* curInst, const NodeID i)
{
const MemObj* mem = getMemObj(curInst);
ConstantDataObjVar* node = new ConstantDataObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}

inline NodeID addConstantObjNode(const SVFValue* curInst, const NodeID i)
{
const MemObj* mem = getMemObj(curInst);
ConstantObjVar* node = new ConstantObjVar(curInst, mem->getId(), mem);
return addObjNode(mem->getValue(), node, mem->getId());
}


/// Add a temp field value node, this method can only invoked by getGepValVar
NodeID addGepValNode(const SVFValue* curInst,const SVFValue* val, const AccessPath& ap, NodeID i, const SVFType* type);
/// Add a field obj node, this method can only invoked by getGepObjVar
Expand Down

0 comments on commit 5d9d52b

Please sign in to comment.