30#ifndef INCLUDE_SVF_FE_LLVMUTIL_H_
31#define INCLUDE_SVF_FE_LLVMUTIL_H_
38#include <llvm/Config/llvm-config.h>
39#include <llvm/TargetParser/Triple.h>
70 if (fpValue->isNormalFP())
72 const llvm::fltSemantics& semantics = fpValue->getValueAPF().getSemantics();
73 if (&semantics == &llvm::APFloat::IEEEhalf() ||
74 &semantics == &llvm::APFloat::IEEEsingle() ||
75 &semantics == &llvm::APFloat::IEEEdouble() ||
76 &semantics == &llvm::APFloat::IEEEquad() ||
77 &semantics == &llvm::APFloat::x87DoubleExtended())
79 dval = fpValue->getValueAPF().convertToDouble();
83 assert (
false &&
"Unsupported floating point type");
97 if (intValue->getBitWidth() <= 64 && intValue->getBitWidth() >= 1)
98 return std::make_pair(intValue->getSExtValue(), intValue->getZExtValue());
100 return std::make_pair(0,0);
106 assert(
isCallSite(value) &&
"not a callsite?");
129 return fun && fun->getName() == main_name;
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 assert(mod &&
"null module");
330#if LLVM_VERSION_MAJOR >= 21
331 return mod->getTargetTriple();
333 return llvm::Triple(mod->getTargetTriple());
339 if (triple.isWindowsMSVCEnvironment())
342 if (triple.isWindowsItaniumEnvironment() ||
343 triple.isWindowsGNUEnvironment() ||
344 triple.isWindowsCygwinEnvironment())
352 std::vector<const Instruction*>& instList);
362 return bb != &bb->getParent()->getEntryBlock() &&
367bool isIRFile(
const std::string& filename);
371 std::vector<std::string>& moduleNameVec);
449 for (
auto it = module.begin(), eit = module.end(); it != eit; ++it)
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)
static TargetABI detectTargetABI(const llvm::Triple &triple)
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.
static llvm::Triple getTargetTriple(const Module *mod)
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).
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)
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
LLVM_NODISCARD bool isa(const Y &Val)
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
llvm::DataLayout DataLayout
llvm::BasicBlock BasicBlock
llvm::ConstantData ConstantData
llvm::MetadataAsValue MetadataAsValue
llvm::Instruction Instruction
llvm::ConstantAggregate ConstantAggregate
TargetABI
C++ ABI inferred from the target triple.
llvm::Value Value
LLVM Basic classes.
llvm::ConstantExpr ConstantExpr
llvm::BlockAddress BlockAddress
llvm::ConstantFP ConstantFP
llvm::ConstantInt ConstantInt