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);
59 assert(
isCallSite(value) &&
"not a callsite?");
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);
183 if (
const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
185 if (constExpr->getOpcode() == Instruction::GetElementPtr)
193 if (
const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
195 if (constExpr->getOpcode() == Instruction::IntToPtr)
203 if (
const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
205 if (constExpr->getOpcode() == Instruction::PtrToInt)
213 if (
const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
215 if (constExpr->getOpcode() == Instruction::BitCast)
223 if (
const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
225 if (constExpr->getOpcode() == Instruction::Select)
233 if (
const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
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)
247 if (
const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
249 if (constExpr->getOpcode() == Instruction::ICmp ||
250 constExpr->getOpcode() == Instruction::FCmp)
258 if (
const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
260 if ((constExpr->getOpcode() >= Instruction::BinaryOpsBegin) &&
261 (constExpr->getOpcode() <= Instruction::BinaryOpsEnd))
269 if (
const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
271 if ((constExpr->getOpcode() >= Instruction::UnaryOpsBegin) &&
272 (constExpr->getOpcode() <= Instruction::UnaryOpsEnd))
289 std::vector<const Instruction*>& instList);
299 return bb != &bb->getParent()->getEntryBlock() &&
307 void processArguments(
int argc,
char** argv,
int& arg_num,
char** arg_value,
308 std::vector<std::string>& moduleNameVec);
369 for (
auto it = module.begin(), eit = module.end(); it != eit; ++it)
bool isIntrinsicInst(const Instruction *inst)
Return true if it is an intrinsic instruction.
const CallBase * getLLVMCallSite(const Value *value)
Return LLVM callsite given a value.
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)
static DataLayout * getDataLayout(Module *mod)
bool isNoCallerFunction(const Function *fun)
Function does not have any possible caller in the call graph.
const Value * getFirstUseViaCastInst(const Value *val)
const ConstantExpr * isUnaryConstantExpr(const Value *val)
bool isHeapAllocExtCall(const Instruction *inst)
const ConstantExpr * isPtr2IntConstantExpr(const Value *val)
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 ConstantExpr * isBinaryConstantExpr(const Value *val)
const Value * stripAllCasts(const Value *val)
Strip off the all casts.
bool isArgOfUncalledFunction(const Value *val)
Return true if the argument in a function does not have a caller.
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 ArgInDeadFunction(const Value *val)
whether this is an argument in dead function
bool functionDoesNotRet(const Function *fun)
std::string dumpType(const Type *type)
void getNextInsts(const Instruction *curInst, std::vector< const Instruction * > &instList)
Get the next instructions following control flow.
const Function * getProgEntryFunction(Module &module)
Get program entry function from module.
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 * isTruncConstantExpr(const Value *val)
const Value * getGlobalRep(const Value *val)
find the unique defined global across multiple modules
void getFunReachableBBs(const Function *svfFun, std::vector< const SVFBasicBlock * > &bbs)
Get reachable basic block from function entry.
const ConstantExpr * isCmpConstantExpr(const Value *val)
u32_t getNumOfElements(const Type *ety)
Return size of this object based on LLVM value.
const ConstantExpr * isGepConstantExpr(const Value *val)
Return corresponding constant expression, otherwise return nullptr.
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.
static Type * getPtrElementType(const PointerType *pty)
void viewCFG(const Function *fun)
bool isBlackholeSym(const Value *val)
Check whether this value is a black hole.
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.
const Function * getCallee(const CallBase *cs)
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)
const ConstantExpr * isInt2PtrConstantExpr(const Value *val)
const ConstantExpr * isSelectConstantExpr(const Value *val)
std::string restoreFuncName(std::string funcName)
const Function * getLLVMFunction(const Value *val)
Return LLVM function if this value is.
bool isNonInstricCallSite(const Instruction *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
const ConstantExpr * isCastConstantExpr(const Value *val)
std::string dumpValue(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::BlockAddress BlockAddress
llvm::PointerType PointerType