30#ifndef INCLUDE_SVF_FE_LLVMUTIL_H_
31#define INCLUDE_SVF_FE_LLVMUTIL_H_
47 return SVFUtil::isa<CallBase>(inst);
52 return SVFUtil::isa<CallBase>(
val);
61 if (&
semantics == &llvm::APFloat::IEEEhalf() ||
62 &
semantics == &llvm::APFloat::IEEEsingle() ||
63 &
semantics == &llvm::APFloat::IEEEdouble() ||
64 &
semantics == &llvm::APFloat::IEEEquad() ||
65 &
semantics == &llvm::APFloat::x87DoubleExtended())
67 dval =
fpValue->getValueAPF().convertToDouble();
71 assert (
false &&
"Unsupported floating point type");
88 return std::make_pair(0,0);
95 return SVFUtil::cast<CallBase>(value);
101 return SVFUtil::dyn_cast<Function>(cs->getCalledOperand()->stripPointerCasts());
107 return SVFUtil::dyn_cast<Function>(
val->stripPointerCasts());
117 return fun && fun->getName() ==
main_name;
123 return SVFUtil::isa<UndefValue>(
val);
129 return SVFUtil::dyn_cast<ConstantPointerNull>(
val);
134#if (LLVM_VERSION_MAJOR < 14)
135 return pty->getPointerElementType();
136#elif (LLVM_VERSION_MAJOR < 17)
137 assert(!
pty->isOpaque() &&
"Opaque Pointer is used, please recompile the source adding '-Xclang -no-opaque-pointers'");
138 return pty->getNonOpaquePointerElementType();
140 assert(
false &&
"llvm version 17+ only support opaque pointers!");
160 return SVFUtil::isa<Argument>(
val)
168 return SVFUtil::isa<Argument>(
val) &&
170 SVFUtil::cast<Argument>(
val)->getParent());
189 return SVFUtil::isa<Argument>(
val)
203 std::vector<const SVFBasicBlock*>&
bbs);
221 if (
constExpr->getOpcode() == Instruction::GetElementPtr)
231 if (
constExpr->getOpcode() == Instruction::IntToPtr)
241 if (
constExpr->getOpcode() == Instruction::PtrToInt)
251 if (
constExpr->getOpcode() == Instruction::BitCast)
261 if (
constExpr->getOpcode() == Instruction::Select)
271 if (
constExpr->getOpcode() == Instruction::Trunc ||
272 constExpr->getOpcode() == Instruction::FPTrunc ||
273 constExpr->getOpcode() == Instruction::ZExt ||
274 constExpr->getOpcode() == Instruction::SExt ||
275 constExpr->getOpcode() == Instruction::FPExt)
285 if (
constExpr->getOpcode() == Instruction::ICmp ||
286 constExpr->getOpcode() == Instruction::FCmp)
296 if ((
constExpr->getOpcode() >= Instruction::BinaryOpsBegin) &&
297 (
constExpr->getOpcode() <= Instruction::BinaryOpsEnd))
307 if ((
constExpr->getOpcode() >= Instruction::UnaryOpsBegin) &&
308 (
constExpr->getOpcode() <= Instruction::UnaryOpsEnd))
319#if LLVM_VERSION_MAJOR >= 19
329 std::vector<const Instruction*>&
instList);
339 return bb != &bb->getParent()->getEntryBlock() &&
static Option< bool > SVFMain
bool isIntrinsicInst(const Instruction *inst)
Return true if it is an intrinsic instruction.
const Function * getProgFunction(const std::string &funName)
Get program entry function from module.
const Value * stripConstantCasts(const Value *val)
Strip off the constant casts.
bool isPtrInUncalledFunction(const Value *value)
Return true if this is value in a dead function (function without any caller)
bool isHeapAllocExtCallViaRet(const Instruction *inst)
bool isNoCallerFunction(const Function *fun)
Function does not have any possible caller in the call graph.
const Value * getFirstUseViaCastInst(const Value *val)
const CallBase * getLLVMCallSite(const Value *value)
Return LLVM callsite given a value.
const ConstantExpr * isBinaryConstantExpr(const Value *val)
bool isHeapAllocExtCall(const Instruction *inst)
void viewCFGOnly(const Function *fun)
const std::string getSourceLocOfFunction(const Function *F)
bool isUncalledFunction(const Function *fun)
whether this is a function without any possible caller?
double getDoubleValue(const ConstantFP *fpValue)
bool isConstantObjSym(const Value *val)
Check whether this value points-to a constant object.
const Value * stripAllCasts(const Value *val)
Strip off the all casts.
const ConstantExpr * isInt2PtrConstantExpr(const Value *val)
bool isArgOfUncalledFunction(const Value *val)
Return true if the argument in a function does not have a caller.
const ConstantExpr * isSelectConstantExpr(const Value *val)
bool isMemcpyExtFun(const Function *fun)
bool isIntrinsicFun(const Function *func)
std::vector< const Function * > getCalledFunctions(const Function *F)
Get all called funcions in a parent function.
bool isNoPrecessorBasicBlock(const BasicBlock *bb)
bool isCallSite(const Instruction *inst)
Whether an instruction is a call or invoke instruction.
bool isStackAllocExtCall(const Instruction *inst)
bool ArgInDeadFunction(const Value *val)
whether this is an argument in dead function
bool functionDoesNotRet(const Function *fun)
const ConstantExpr * isTruncConstantExpr(const Value *val)
std::string dumpType(const Type *type)
std::pair< s64_t, u64_t > getIntegerValue(const ConstantInt *intValue)
void getNextInsts(const Instruction *curInst, std::vector< const Instruction * > &instList)
Get the next instructions following control flow.
bool isNullPtrSym(const Value *val)
Check whether this value is a black hole.
std::string dumpValueAndDbgInfo(const Value *val)
bool isConstDataOrAggData(const Value *val)
Return true if the value refers to constant data, e.g., i32 0.
const std::string getSourceLoc(const Value *val)
const ConstantExpr * isPtr2IntConstantExpr(const Value *val)
bool isHeapObj(const Value *val)
const Value * getGlobalRep(const Value *val)
find the unique defined global across multiple modules
const ConstantExpr * isUnaryConstantExpr(const Value *val)
void getFunReachableBBs(const Function *svfFun, std::vector< const SVFBasicBlock * > &bbs)
Get reachable basic block from function entry.
const ConstantExpr * isCastConstantExpr(const Value *val)
bool isExtCall(const Function *fun)
u32_t getNumOfElements(const Type *ety)
Return size of this object based on LLVM value.
const Function * getProgEntryFunction(Module &module)
Get program entry function from module.
bool basicBlockHasRetInst(const BasicBlock *bb)
Return true if the function has a return instruction.
void viewCFG(const Function *fun)
bool isBlackholeSym(const Value *val)
Check whether this value is a black hole.
bool isStackObj(const Value *val)
bool isHeapAllocExtCallViaArg(const Instruction *inst)
bool isMemsetExtFun(const Function *fun)
bool isProgEntryFunction(const Function *fun)
Check whether a function is an entry function (i.e., main)
bool isObject(const Value *ref)
Return true if this value refers to a object.
void processArguments(int argc, char **argv, int &arg_num, char **arg_value, std::vector< std::string > &moduleNameVec)
Parse argument for multi-module analysis.
bool isIRFile(const std::string &filename)
Check whether a file is an LLVM IR file.
bool ArgInProgEntryFunction(const Value *val)
Return true if this is an argument of a program entry function (e.g. main)
static Type * getPtrElementType(const PointerType *pty)
bool isStackAllocExtCallViaRet(const Instruction *inst)
const Function * getLLVMFunction(const Value *val)
Return LLVM function if this value is.
const ConstantExpr * isGepConstantExpr(const Value *val)
Return corresponding constant expression, otherwise return nullptr.
u32_t getHeapAllocHoldingArgPosition(const Function *fun)
static DataLayout * getDataLayout(Module *mod)
std::string restoreFuncName(std::string funcName)
const Function * getCallee(const CallBase *cs)
const FunObjVar * getFunObjVar(const std::string &name)
bool isNonInstricCallSite(const Instruction *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
std::string dumpValue(const Value *val)
const ConstantExpr * isCmpConstantExpr(const Value *val)
LLVM_NODISCARD bool isa(const Y &Val)
llvm::DataLayout DataLayout
llvm::BasicBlock BasicBlock
llvm::ConstantData ConstantData
llvm::MetadataAsValue MetadataAsValue
llvm::Instruction Instruction
llvm::ConstantAggregate ConstantAggregate
llvm::Value Value
LLVM Basic classes.
llvm::ConstantExpr ConstantExpr
llvm::IRBuilder IRBuilder
llvm::BlockAddress BlockAddress
llvm::PointerType PointerType
llvm::ConstantFP ConstantFP
llvm::ConstantInt ConstantInt