Skip to content

Commit

Permalink
Merge pull request #1655 from jumormt/2.11.2
Browse files Browse the repository at this point in the history
remove svfconstantint,fp,null
  • Loading branch information
yuleisui authored Feb 13, 2025
2 parents 06e5c50 + 80c448c commit a572577
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 184 deletions.
135 changes: 3 additions & 132 deletions svf-llvm/include/SVF-LLVM/SVFLLVMValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ class SVFLLVMValue
SVFArg,
SVFConst,
SVFConstData,
SVFConstInt,
SVFConstFP,
SVFNullPtr,
SVFBlackHole,
SVFMetaAsValue,
SVFOther
};
Expand Down Expand Up @@ -138,14 +134,6 @@ class SVFLLVMValue
{
return ptrInUncalledFun;
}
inline bool isblackHole() const
{
return getKind() == SVFBlackHole;;
}
inline bool isNullPtr() const
{
return getKind() == SVFNullPtr;
}
inline virtual void setSourceLoc(const std::string& sourceCodeInfo)
{
sourceLoc = sourceCodeInfo;
Expand Down Expand Up @@ -526,11 +514,7 @@ class SVFConstant : public SVFLLVMValue
{
return node->getKind() == SVFConst ||
node->getKind() == SVFGlob ||
node->getKind() == SVFConstData ||
node->getKind() == SVFConstInt ||
node->getKind() == SVFConstFP ||
node->getKind() == SVFNullPtr ||
node->getKind() == SVFBlackHole;
node->getKind() == SVFConstData;
}

};
Expand Down Expand Up @@ -629,124 +613,11 @@ class SVFConstantData : public SVFConstant

static inline bool classof(const SVFLLVMValue *node)
{
return node->getKind() == SVFConstData ||
node->getKind() == SVFConstInt ||
node->getKind() == SVFConstFP ||
node->getKind() == SVFNullPtr ||
node->getKind() == SVFBlackHole;
}
static inline bool classof(const SVFConstantData *node)
{
return node->getKind() == SVFConstData ||
node->getKind() == SVFConstInt ||
node->getKind() == SVFConstFP ||
node->getKind() == SVFNullPtr ||
node->getKind() == SVFBlackHole;
}
};

class SVFConstantInt : public SVFConstantData
{
friend class SVFIRWriter;
friend class SVFIRReader;
private:
u64_t zval;
s64_t sval;
public:
SVFConstantInt(const SVFType* ty, u64_t z, s64_t s)
: SVFConstantData(ty, SVFLLVMValue::SVFConstInt), zval(z), sval(s)
{
}
SVFConstantInt() = delete;

static inline bool classof(const SVFLLVMValue *node)
{
return node->getKind() == SVFConstInt;
}
static inline bool classof(const SVFConstantData *node)
{
return node->getKind() == SVFConstInt;
}
// Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate for the type of this constant.
inline u64_t getZExtValue () const
{
return zval;
}
// Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the type of this constant
inline s64_t getSExtValue () const
{
return sval;
}
};

class SVFConstantFP : public SVFConstantData
{
friend class SVFIRWriter;
friend class SVFIRReader;
private:
float dval;
public:
SVFConstantFP(const SVFType* ty, double d)
: SVFConstantData(ty, SVFLLVMValue::SVFConstFP), dval(d)
{
}
SVFConstantFP() = delete;

inline double getFPValue () const
{
return dval;
}
static inline bool classof(const SVFLLVMValue *node)
{
return node->getKind() == SVFConstFP;
}
static inline bool classof(const SVFConstantData *node)
{
return node->getKind() == SVFConstFP;
}
};

class SVFConstantNullPtr : public SVFConstantData
{
friend class SVFIRWriter;
friend class SVFIRReader;

public:
SVFConstantNullPtr(const SVFType* ty)
: SVFConstantData(ty, SVFLLVMValue::SVFNullPtr)
{
}
SVFConstantNullPtr() = delete;

static inline bool classof(const SVFLLVMValue *node)
{
return node->getKind() == SVFNullPtr;
}
static inline bool classof(const SVFConstantData *node)
{
return node->getKind() == SVFNullPtr;
}
};

class SVFBlackHoleValue : public SVFConstantData
{
friend class SVFIRWriter;
friend class SVFIRReader;

public:
SVFBlackHoleValue(const SVFType* ty)
: SVFConstantData(ty, SVFLLVMValue::SVFBlackHole)
{
}
SVFBlackHoleValue() = delete;

static inline bool classof(const SVFLLVMValue *node)
{
return node->getKind() == SVFBlackHole;
return node->getKind() == SVFConstData;
}
static inline bool classof(const SVFConstantData *node)
{
return node->getKind() == SVFBlackHole;
return node->getKind() == SVFConstData;
}
};

Expand Down
57 changes: 5 additions & 52 deletions svf-llvm/lib/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,9 +1211,10 @@ void LLVMModuleSet::dumpModulesToFile(const std::string& suffix)

NodeID LLVMModuleSet::getValueNode(const SVFLLVMValue *val)
{
if (val->isNullPtr())
auto llvm_value = llvmModuleSet->getLLVMValue(val);
if (SVFUtil::isa<ConstantPointerNull>(llvm_value))
return svfir->nullPtrSymID();
else if (val->isblackHole())
else if (SVFUtil::isa<UndefValue>(llvm_value))
return svfir->blkPtrSymID();
else
{
Expand All @@ -1224,7 +1225,7 @@ NodeID LLVMModuleSet::getValueNode(const SVFLLVMValue *val)
}
bool LLVMModuleSet::hasValueNode(const SVFLLVMValue *val)
{
if (val->isNullPtr() || val->isblackHole())
if (SVFUtil::isa<ConstantPointerNull, UndefValue>(llvmModuleSet->getLLVMValue(val)))
return true;
else
return (valSymMap.find(val) != valSymMap.end());
Expand Down Expand Up @@ -1326,55 +1327,7 @@ SVFConstantData* LLVMModuleSet::getSVFConstantData(const ConstantData* cd)
}
else
{
SVFConstantData* svfcd = nullptr;
if(const ConstantInt* cint = SVFUtil::dyn_cast<ConstantInt>(cd))
{
/// bitwidth == 1 : cint has value from getZExtValue() because `bool true` will be translated to -1 using sign extension (i.e., getSExtValue).
/// bitwidth <=64 1 : cint has value from getSExtValue()
/// bitwidth >64 1 : cint has value 0 because it represents an invalid int
if(cint->getBitWidth() == 1)
svfcd = new SVFConstantInt(getSVFType(cint->getType()), cint->getZExtValue(), cint->getZExtValue());
else if(cint->getBitWidth() <= 64 && cint->getBitWidth() > 1)
svfcd = new SVFConstantInt(getSVFType(cint->getType()), cint->getZExtValue(), cint->getSExtValue());
else
svfcd = new SVFConstantInt(getSVFType(cint->getType()), 0, 0);
}
else if(const ConstantFP* cfp = SVFUtil::dyn_cast<ConstantFP>(cd))
{
double dval = 0;
// TODO: Why only double is considered? What about float?
if (cfp->isNormalFP())
{
const llvm::fltSemantics& semantics = cfp->getValueAPF().getSemantics();
if (&semantics == &llvm::APFloat::IEEEhalf() ||
&semantics == &llvm::APFloat::IEEEsingle() ||
&semantics == &llvm::APFloat::IEEEdouble() ||
&semantics == &llvm::APFloat::IEEEquad() ||
&semantics == &llvm::APFloat::x87DoubleExtended())
{
dval = cfp->getValueAPF().convertToDouble();
}
else
{
assert (false && "Unsupported floating point type");
abort();
}
}
else
{
// other cfp type, like isZero(), isInfinity(), isNegative(), etc.
// do nothing
}
svfcd = new SVFConstantFP(getSVFType(cd->getType()), dval);
}
else if(SVFUtil::isa<ConstantPointerNull>(cd))
svfcd = new SVFConstantNullPtr(getSVFType(cd->getType()));
else if (SVFUtil::isa<UndefValue>(cd))
svfcd = new SVFBlackHoleValue(getSVFType(cd->getType()));
else
svfcd = new SVFConstantData(getSVFType(cd->getType()));


SVFConstantData* svfcd = new SVFConstantData(getSVFType(cd->getType()));
svfModule->addConstant(svfcd);
addConstantDataMap(cd,svfcd);
return svfcd;
Expand Down

0 comments on commit a572577

Please sign in to comment.