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);
60 return SVFUtil::cast<CallBase>(value);
66 return SVFUtil::dyn_cast<Function>(cs->getCalledOperand()->stripPointerCasts());
72 return SVFUtil::dyn_cast<Function>(
val->stripPointerCasts());
81 return fun && fun->getName() ==
"main";
87 return SVFUtil::isa<UndefValue>(
val);
93 return SVFUtil::dyn_cast<ConstantPointerNull>(
val);
98#if (LLVM_VERSION_MAJOR < 14)
99 return pty->getPointerElementType();
100#elif (LLVM_VERSION_MAJOR < 17)
101 assert(!
pty->isOpaque() &&
"Opaque Pointer is used, please recompile the source adding '-Xclang -no-opaque-pointers'");
102 return pty->getNonOpaquePointerElementType();
104 assert(
false &&
"llvm version 17+ only support opaque pointers!");
124 return SVFUtil::isa<Argument>(
val)
132 return SVFUtil::isa<Argument>(
val) &&
134 SVFUtil::cast<Argument>(
val)->getParent());
153 return SVFUtil::isa<Argument>(
val)
167 std::vector<const SVFBasicBlock*>&
bbs);
185 if (
constExpr->getOpcode() == Instruction::GetElementPtr)
195 if (
constExpr->getOpcode() == Instruction::IntToPtr)
205 if (
constExpr->getOpcode() == Instruction::PtrToInt)
215 if (
constExpr->getOpcode() == Instruction::BitCast)
225 if (
constExpr->getOpcode() == Instruction::Select)
235 if (
constExpr->getOpcode() == Instruction::Trunc ||
236 constExpr->getOpcode() == Instruction::FPTrunc ||
237 constExpr->getOpcode() == Instruction::ZExt ||
238 constExpr->getOpcode() == Instruction::SExt ||
239 constExpr->getOpcode() == Instruction::FPExt)
249 if (
constExpr->getOpcode() == Instruction::ICmp ||
250 constExpr->getOpcode() == Instruction::FCmp)
260 if ((
constExpr->getOpcode() >= Instruction::BinaryOpsBegin) &&
261 (
constExpr->getOpcode() <= Instruction::BinaryOpsEnd))
271 if ((
constExpr->getOpcode() >= Instruction::UnaryOpsBegin) &&
272 (
constExpr->getOpcode() <= Instruction::UnaryOpsEnd))
289 std::vector<const Instruction*>&
instList);
299 return bb != &bb->getParent()->getEntryBlock() &&
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?
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 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)
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)
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.
const SVFFunction * getFunction(const std::string &name)
Get the corresponding Function based on its name.
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 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 isConstantObjSym(const SVFValue *val)
Check whether this value points-to a constant object.
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.
static DataLayout * getDataLayout(Module *mod)
std::string restoreFuncName(std::string funcName)
const Function * getCallee(const CallBase *cs)
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