40 #include "llvm/Support/FileSystem.h"
42 #include "llvm/Transforms/Utils/Cloning.h"
73 #define SVF_MAIN_FUNC_NAME "svf.main"
74 #define SVF_GLOBAL_CTORS "llvm.global_ctors"
75 #define SVF_GLOBAL_DTORS "llvm.global_dtors"
78 bool LLVMModuleSet::preProcessed =
false;
80 LLVMModuleSet::LLVMModuleSet()
91 item.second =
nullptr;
108 mset->
modules.emplace_back(mod);
128 if (!moduleNameVec.empty())
186 std::vector<const Function*> candidateDefs, candidateDecls;
191 for (
Function& func : mod.functions())
193 if (func.isDeclaration())
195 candidateDecls.push_back(&func);
199 candidateDefs.push_back(&func);
204 for (
const Function* func: candidateDefs)
208 for (
const Function* func: candidateDecls)
227 global.getName().str(),
getSVFType(global.getType()));
236 alias.getName().str(),
getSVFType(alias.getType()));
245 ifunc.getName().str(),
getSVFType(ifunc.getType()));
256 SVFUtil::cast<SVFFunctionType>(
263 for (
const Argument& arg : func->args())
266 getSVFType(arg.getType()), svfFunc, arg.getArgNo(),
270 svfarg->
setName(std::to_string(arg.getArgNo()));
285 if (
const CallBase* call = SVFUtil::dyn_cast<CallBase>(&inst))
290 call->getFunctionType()->isVarArg(),
291 inst.isTerminator());
295 call->getFunctionType()->isVarArg(),
296 inst.isTerminator());
302 svfBB, inst.isTerminator(),
303 SVFUtil::isa<ReturnInst>(inst));
316 for (
const Function& f : mod.functions())
332 for (Function::const_iterator bit = func->begin(), ebit = func->end(); bit != ebit; ++bit)
353 SVFUtil::isa<ReturnInst>(bb->back())) &&
354 "last inst must be return inst");
359 for (BasicBlock::const_iterator iit = bb->begin(), eiit = bb->end(); iit != eiit; ++iit)
362 if(
const CallBase* call = SVFUtil::dyn_cast<CallBase>(inst))
365 SVFCallInst* svfcall = SVFUtil::cast<SVFCallInst>(svfinst);
366 auto called_llvmval = call->getCalledOperand()->stripPointerCasts();
367 if (
const Function* called_llvmfunc = SVFUtil::dyn_cast<Function>(called_llvmval))
382 for(
u32_t i = 0; i < call->arg_size(); i++)
396 SVFUtil::isa<ReturnInst>(&func->back().back())) &&
397 "last inst must be return inst");
405 if (fun->isDeclaration())
410 dt.recalculate(
const_cast<Function&
>(*fun));
417 for (DominanceFrontierBase::const_iterator dfIter = df.begin(), eDfIter = df.end(); dfIter != eDfIter; dfIter++)
420 const std::set<BasicBlock* >& domSet = dfIter->second;
427 std::vector<const SVFBasicBlock*> reachableBBs;
431 for (Function::const_iterator bit = fun->begin(), beit = fun->end(); bit!=beit; ++bit)
438 for (
const auto domBB : *dtNode)
441 bbSet.insert(domSVFBB);
447 u32_t level = pdtNode->getLevel();
449 BasicBlock* idomBB = pdtNode->getIDom()->getBlock();
454 for (
const auto domBB : *pdtNode)
457 bbSet.insert(domSVFBB);
461 if (
const Loop* loop = loopInfo.getLoopFor(&bb))
463 for (
const BasicBlock* loopBlock : loop->getBlocks())
479 std::unique_ptr<BreakConstantGEPs> p1 = std::make_unique<BreakConstantGEPs>();
486 std::unique_ptr<UnifyFunctionExitNodes> p2 =
487 std::make_unique<UnifyFunctionExitNodes>();
490 for (
auto F = M.begin(), E = M.end();
F != E; ++
F)
493 if (fun.isDeclaration())
495 p2->runOnFunction(fun);
509 for (
u32_t i = 0; i < moduleNameVec.size(); i++)
511 u32_t lastIndex = moduleNameVec[i].find_last_of(
".");
512 std::string rawName = moduleNameVec[i].substr(0, lastIndex);
513 moduleNameVec[i] = (rawName + preProcessSuffix);
527 if(moduleNameVec.empty())
564 owned_ctx = std::make_unique<LLVMContext>();
565 for (
const std::string& moduleName : moduleNameVec)
569 SVFUtil::errs() <<
"not an IR file: " << moduleName << std::endl;
574 std::unique_ptr<Module> mod = parseIRFile(moduleName, Err, *
owned_ctx);
577 SVFUtil::errs() <<
"load module: " << moduleName <<
"failed!!\n\n";
599 assert(!
empty() &&
"LLVMModuleSet contains no modules; cannot load ExtAPI module without LLVMContext!");
607 SVFUtil::errs() <<
"not an external IR file: " << extModuleName << std::endl;
611 std::unique_ptr<Module> mod = parseIRFile(extModuleName, Err,
getContext());
614 SVFUtil::errs() <<
"load external module: " << extModuleName <<
"failed!!\n\n";
648 class LLVMGlobalFunction
653 LLVMGlobalFunction() {};
655 : priority(_priority), func(_func) {};
656 bool operator>(
const LLVMGlobalFunction &other)
const
658 if (priority != other.priority)
660 return priority > other.priority;
664 return func > other.func;
669 std::priority_queue<LLVMGlobalFunction, std::vector<LLVMGlobalFunction>,
670 greater<LLVMGlobalFunction>>
672 std::vector<const Function* > result;
678 SVFUtil::dyn_cast<ConstantArray>(global->getInitializer()))
681 for (
unsigned int i = 0; i < globalFuncArray->getNumOperands(); ++i)
685 SVFUtil::dyn_cast<ConstantStruct>(
686 globalFuncArray->getOperand(i)))
690 const ConstantInt* priority = SVFUtil::dyn_cast<ConstantInt>(
691 globalFuncItem->getOperand(0));
692 const Function* func = SVFUtil::dyn_cast<Function>(
693 globalFuncItem->getOperand(1));
695 if (priority && func)
697 queue.push(LLVMGlobalFunction(priority
706 while (!queue.empty())
708 result.push_back(queue.top().func);
716 std::vector<const Function*> ctor_funcs;
717 std::vector<const Function*> dtor_funcs;
719 Module* mainMod =
nullptr;
730 else if (global.getName().equals(
SVF_GLOBAL_DTORS) && global.hasInitializer())
737 for (
auto &func : mod)
739 auto funName = func.getName();
743 if (funName.equals(
"main"))
754 (ctor_funcs.size() > 0 || dtor_funcs.size() > 0))
756 assert(mainMod &&
"Module with main function not found.");
759 Type* ptr = PointerType::getUnqual(M.getContext());
760 Type* i32 = IntegerType::getInt32Ty(M.getContext());
762 #if (LLVM_VERSION_MAJOR >= 9)
763 FunctionCallee svfmainFn = M.getOrInsertFunction(
765 Type::getVoidTy(M.getContext()),
768 Function* svfmain = SVFUtil::dyn_cast<Function>(svfmainFn.getCallee());
770 Function* svfmain = SVFUtil::dyn_cast<Function>(M.getOrInsertFunction(
772 Type::getVoidTy(M.getContext()),
776 svfmain->setCallingConv(llvm::CallingConv::C);
777 BasicBlock* block = BasicBlock::Create(M.getContext(),
"entry", svfmain);
781 for (
auto& ctor : ctor_funcs)
783 auto target = M.getOrInsertFunction(
785 Type::getVoidTy(M.getContext())
787 Builder.CreateCall(target);
791 Function::arg_iterator arg_it = svfmain->arg_begin();
792 Value* args[] = {arg_it, arg_it + 1, arg_it + 2};
793 size_t cnt = orgMain->arg_size();
794 assert(cnt <= 3 &&
"Too many arguments for main()");
795 Builder.CreateCall(orgMain, llvm::ArrayRef<Value*>(args, args + cnt));
798 for (
auto& dtor : dtor_funcs)
800 auto target = M.getOrInsertFunction(dtor->getName(), Type::getVoidTy(M.getContext()));
801 Builder.CreateCall(target);
804 Builder.CreateRetVoid();
810 GlobalVariable *glob = mod->getGlobalVariable(
"llvm.global.annotations");
811 if (glob ==
nullptr || !glob->hasInitializer())
814 ConstantArray *ca = SVFUtil::dyn_cast<ConstantArray>(glob->getInitializer());
818 for (
unsigned i = 0; i < ca->getNumOperands(); ++i)
820 ConstantStruct *structAn = SVFUtil::dyn_cast<ConstantStruct>(ca->getOperand(i));
821 if (structAn ==
nullptr || structAn->getNumOperands() == 0)
828 if (
ConstantExpr *expr = SVFUtil::dyn_cast<ConstantExpr>(structAn->getOperand(0)))
830 if (expr->getOpcode() == Instruction::BitCast && SVFUtil::isa<Function>(expr->getOperand(0)))
831 fun = SVFUtil::cast<Function>(expr->getOperand(0));
833 ConstantExpr *note = SVFUtil::cast<ConstantExpr>(structAn->getOperand(1));
834 if (note->getOpcode() != Instruction::GetElementPtr)
837 annotateStr = SVFUtil::dyn_cast<GlobalVariable>(note->getOperand(0));
842 fun = SVFUtil::dyn_cast<Function>(structAn->getOperand(0));
843 annotateStr = SVFUtil::dyn_cast<GlobalVariable>(structAn->getOperand(1));
846 if (!fun || annotateStr ==
nullptr || !annotateStr->hasInitializer())
850 if (data && data->isString())
852 std::string annotation = data->getAsString().str();
853 if (!annotation.empty())
881 Module* appModule =
nullptr;
882 Module* extModule =
nullptr;
891 for (
const Function& fun : mod.functions())
895 if (fun.getName().str() ==
"main")
897 appFunDecls.insert(&fun);
898 appFuncDeclNames.insert(fun.getName().str());
901 else if (fun.getName().str() ==
"svf__main")
907 extFuncs.insert(&fun);
908 extFunDefNames.insert(fun.getName().str());
916 for (
const Function& fun : mod.functions())
918 if (fun.isDeclaration())
920 appFunDecls.insert(&fun);
921 appFuncDeclNames.insert(fun.getName().str());
925 appFunDefs.insert(&fun);
926 appFuncDefNames.insert(fun.getName().str());
933 std::set_intersection(
934 appFuncDefNames.begin(), appFuncDefNames.end(), extFunDefNames.begin(), extFunDefNames.end(),
935 std::inserter(intersectNames, intersectNames.end()));
939 assert(!(appFunToReplace ==
NULL && appModule ==
NULL) &&
"appFunToReplace and appModule cannot both be NULL");
943 appModule = appFunToReplace->getParent();
946 Function *clonedFunction = Function::Create(extFunToClone->getFunctionType(), Function::ExternalLinkage, extFunToClone->getName(), appModule);
948 llvm::ValueToValueMapTy valueMap;
949 Function::arg_iterator destArg = clonedFunction->arg_begin();
950 for (Function::const_arg_iterator srcArg = extFunToClone->arg_begin(); srcArg != extFunToClone->arg_end(); ++srcArg)
952 destArg->setName(srcArg->getName());
953 valueMap[&*srcArg] = &*destArg++;
958 llvm::SmallVector<ReturnInst*, 8> ignoredReturns;
959 CloneFunctionInto(clonedFunction, extFunToClone, valueMap, llvm::CloneFunctionChangeType::LocalChangesOnly, ignoredReturns,
"",
nullptr);
964 appFunToReplace->replaceAllUsesWith(clonedFunction);
965 std::string oldFunctionName = appFunToReplace->getName().str();
967 appFunToReplace->eraseFromParent();
968 clonedFunction->setName(oldFunctionName);
970 return clonedFunction;
974 for (
const Function* appFunDecl : appFunDecls)
977 for (
const Function* extFun : extFuncs)
979 if (extFun->getName().str().compare(appFunDeclName) == 0)
985 Function* clonedFunction = cloneAndReplaceFunction(
const_cast<Function*
>(extFun),
const_cast<Function*
>(appFunDecl),
nullptr,
true);
986 extFuncs2ClonedFuncs[extFun] = clonedFunction;
987 clonedFuncs.insert(clonedFunction);
1000 for (
string sameFuncDef: intersectNames)
1002 Function* appFuncDef = appModule->getFunction(sameFuncDef);
1003 Function* extFuncDef = extModule->getFunction(sameFuncDef);
1004 if (appFuncDef ==
nullptr || extFuncDef ==
nullptr)
1007 FunctionType *appFuncDefType = appFuncDef->getFunctionType();
1008 FunctionType *extFuncDefType = extFuncDef->getFunctionType();
1009 if (appFuncDefType != extFuncDefType)
1015 std::vector<std::string> annotations = it->second;
1016 if (annotations.size() == 1 && annotations[0].find(
"OVERWRITE") != std::string::npos)
1018 Function* clonedFunction = cloneAndReplaceFunction(
const_cast<Function*
>(extFuncDef),
const_cast<Function*
>(appFuncDef),
nullptr,
true);
1019 extFuncs2ClonedFuncs[extFuncDef] = clonedFunction;
1020 clonedFuncs.insert(clonedFunction);
1024 if (annotations.size() >= 2)
1026 for (
const auto& annotation : annotations)
1028 if(annotation.find(
"OVERWRITE") != std::string::npos)
1030 assert(
false &&
"overwrite and other annotations cannot co-exist");
1040 for (
inst_iterator I = inst_begin(caller), E = inst_end(caller); I != E; ++I)
1044 if (
CallInst *callInst = SVFUtil::dyn_cast<CallInst>(inst))
1046 Function *calledFunc = callInst->getCalledFunction();
1048 if (calledFunc && calledFunc->getName() == callee->getName())
1050 callInst->setCalledFunction(callee);
1057 cloneAndLinkFunction = [&](
const Function* extFunToClone,
Function* appClonedFun)
1059 if (clonedFuncs.find(extFunToClone) != clonedFuncs.end())
1062 Module* appModule = appClonedFun->getParent();
1064 if (appModule->getFunction(extFunToClone->getName()))
1067 Function* func = appModule->getFunction(extFunToClone->getName());
1068 linkFunctions(appClonedFun, func);
1072 bool cloneBody =
true;
1076 std::vector<std::string> annotations = it->second;
1077 if (!(annotations.size() == 1 && annotations[0].find(
"OVERWRITE") != std::string::npos))
1083 Function* clonedFunction = cloneAndReplaceFunction(extFunToClone,
nullptr, appModule, cloneBody);
1085 clonedFuncs.insert(clonedFunction);
1089 linkFunctions(appClonedFun, clonedFunction);
1093 for (
const auto& calledFunction : calledFunctions)
1095 cloneAndLinkFunction(calledFunction, clonedFunction);
1100 for (
const auto& pair : extFuncs2ClonedFuncs)
1106 for (
const auto& extCalledFun : extCalledFuns)
1108 cloneAndLinkFunction(extCalledFun, clonedExtFun);
1121 if (
name != extFun->getName().str())
1123 newKey = extFun->getName().str();
1125 newFun2AnnoMap.insert({newKey, it->second});
1132 [&extModule](
const std::reference_wrapper<llvm::Module>& moduleRef)
1134 return &moduleRef.get() == extModule;
1148 NameToGlobalsMapTy nameToGlobalsMap;
1154 if (global.hasPrivateLinkage())
1156 string name = global.getName().str();
1163 for (
const auto& pair : nameToGlobalsMap)
1168 std::find_if(globals.begin(), globals.end(),
1171 return g->hasInitializer();
1174 repIt != globals.end()
1177 : (assert(!globals.empty() &&
"Empty global set"),
1194 std::size_t pos = moduleName.rfind(
'.');
1195 if (pos != std::string::npos)
1196 OutputFilename = moduleName.substr(0, pos) + suffix;
1198 OutputFilename = moduleName + suffix;
1201 raw_fd_ostream OS(OutputFilename.c_str(), EC, llvm::sys::fs::OF_None);
1203 #if (LLVM_VERSION_MAJOR >= 7)
1204 WriteBitcodeToFile(mod, OS);
1206 WriteBitcodeToFile(&mod, OS);
1218 svfvalue->
setName(val->getName().str());
1224 if (
SVFGlobalValue* glob = SVFUtil::dyn_cast<SVFGlobalValue>(svfvalue))
1227 assert(SVFUtil::isa<GlobalValue>(llvmVal) &&
"not a GlobalValue?");
1228 glob->setDefGlobalForMultipleModule(
getSVFGlobalValue(SVFUtil::cast<GlobalValue>(llvmVal)));
1230 if (
SVFFunction* svffun = SVFUtil::dyn_cast<SVFFunction>(svfvalue))
1232 const Function* func = SVFUtil::cast<Function>(val);
1252 assert(SVFUtil::isa<SVFConstantData>(it->second) &&
"not a SVFConstantData type!");
1253 return SVFUtil::cast<SVFConstantData>(it->second);
1258 if(
const ConstantInt* cint = SVFUtil::dyn_cast<ConstantInt>(cd))
1263 if(cint->getBitWidth() == 1)
1265 else if(cint->getBitWidth() <= 64 && cint->getBitWidth() > 1)
1270 else if(
const ConstantFP* cfp = SVFUtil::dyn_cast<ConstantFP>(cd))
1274 if (cfp->isNormalFP())
1276 const llvm::fltSemantics& semantics = cfp->getValueAPF().getSemantics();
1277 if (&semantics == &llvm::APFloat::IEEEhalf() ||
1278 &semantics == &llvm::APFloat::IEEEsingle() ||
1279 &semantics == &llvm::APFloat::IEEEdouble() ||
1280 &semantics == &llvm::APFloat::IEEEquad() ||
1281 &semantics == &llvm::APFloat::x87DoubleExtended())
1283 dval = cfp->getValueAPF().convertToDouble();
1287 assert (
false &&
"Unsupported floating point type");
1298 else if(SVFUtil::isa<ConstantPointerNull>(cd))
1300 else if (SVFUtil::isa<UndefValue>(cd))
1338 SVFUtil::isa<MetadataAsValue>(ov)
1349 if (
const Function* fun = SVFUtil::dyn_cast<Function>(value))
1351 else if (
const BasicBlock* bb = SVFUtil::dyn_cast<BasicBlock>(value))
1353 else if(
const Instruction* inst = SVFUtil::dyn_cast<Instruction>(value))
1355 else if (
const Argument* arg = SVFUtil::dyn_cast<Argument>(value))
1357 else if (
const Constant* cons = SVFUtil::dyn_cast<Constant>(value))
1359 if (
const ConstantData* cd = SVFUtil::dyn_cast<ConstantData>(cons))
1361 else if (
const GlobalValue* glob = SVFUtil::dyn_cast<GlobalValue>(cons))
1374 if (it->second == T)
1377 assert(
false &&
"can't find the corresponding LLVM Type");
1386 assert(T &&
"SVFType should not be null");
1409 assert (node!=
nullptr &&
"no ICFGNode for this instruction?");
1423 return node !=
nullptr;
1431 assert (node!=
nullptr &&
"no CallICFGNode for this instruction?");
1440 assert (node!=
nullptr &&
"no RetICFGNode for this instruction?");
1447 assert (node!=
nullptr &&
"no IntraICFGNode for this instruction?");
1460 if (
const ArrayType* aty = SVFUtil::dyn_cast<ArrayType>(T))
1464 else if (
const StructType* sty = SVFUtil::dyn_cast<StructType>(T))
1486 "SVFType has been added before");
1494 Type *mut_T =
const_cast<Type *
>(T);
1495 byteSize = DL.getTypeAllocSize(mut_T);
1499 if (SVFUtil::isa<PointerType>(T))
1503 else if (
const IntegerType* intT = SVFUtil::dyn_cast<IntegerType>(T))
1506 unsigned signWidth = intT->getBitWidth();
1507 assert(signWidth < INT16_MAX &&
"Integer width too big");
1508 svfIntT->setSignAndWidth(intT->getSignBit() ? -signWidth : signWidth);
1511 else if (
const FunctionType* ft = SVFUtil::dyn_cast<FunctionType>(T))
1513 else if (
const StructType* st = SVFUtil::dyn_cast<StructType>(T))
1517 svfst->setName(st->getName().str());
1520 else if (
const auto at = SVFUtil::dyn_cast<ArrayType>(T))
1523 svfat->setNumOfElement(at->getNumElements());
1524 svfat->setTypeOfElement(
getSVFType(at->getElementType()));
1530 auto ot =
new SVFOtherType(T->isSingleValueType(), byteSize);
1531 llvm::raw_string_ostream(
buffer) << *T;
1547 u64_t totalElemNum = ty->getNumElements();
1548 const Type* elemTy = ty->getElementType();
1549 while (
const ArrayType* aty = SVFUtil::dyn_cast<ArrayType>(elemTy))
1551 totalElemNum *= aty->getNumElements();
1552 elemTy = aty->getElementType();
1559 if (totalElemNum == 0)
1573 for (
u32_t j = 0; j < nfF; j++)
1581 u32_t outArrayElemNum = ty->getNumElements();
1582 for (
u32_t i = 0; i < outArrayElemNum; ++i)
1584 auto idx = (i * nfE * totalElemNum) / outArrayElemNum;
1588 for (
u32_t i = 0; i < totalElemNum; ++i)
1590 for (
u32_t j = 0; j < nfE; ++j)
1598 "typeForArray size incorrect!!!");
1617 u32_t strideOffset = 0;
1618 for (
const Type* elemTy : structTy->elements())
1624 if (SVFUtil::isa<StructType, ArrayType>(elemTy))
1630 for (
u32_t j = 0; j < nfF; ++j)
1636 strideOffset += nfE;
1637 for (
u32_t tpj = 0; tpj < nfE; ++tpj)
1655 "typeForStruct size incorrect!");
#define SVF_MAIN_FUNC_NAME
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
PTACallGraph * buildSVFIRCallGraph(SVFModule *svfModule)
Buidl SVFIR callgraoh.
std::string getExtBcPath()
static ExtAPI * getExtAPI()
void setExtFuncAnnotations(const SVFFunction *fun, const std::vector< std::string > &funcAnnotations)
void addOtherValueMap(const Value *ov, SVFOtherValue *svfov)
void createSVFFunction(const Function *func)
LLVMType2SVFTypeMap LLVMType2SVFType
std::vector< const Function * > getLLVMGlobalFunctions(const GlobalVariable *global)
SVFOtherValue * getSVFOtherValue(const Value *ov)
void buildSymbolTable() const
void addInstructionMap(const Instruction *inst, SVFInstruction *svfInst)
StInfo * collectTypeInfo(const Type *ty)
Collect a type info.
void initSVFBasicBlock(const Function *func)
SVFConstantData * getSVFConstantData(const ConstantData *cd)
void loadModules(const std::vector< std::string > &moduleNameVec)
ObjTypeInference * typeInference
static void releaseLLVMModuleSet()
static void preProcessBCs(std::vector< std::string > &moduleNameVec)
SVFGlobalValue * getSVFGlobalValue(const GlobalValue *g) const
void addBasicBlockMap(const BasicBlock *bb, SVFBasicBlock *svfBB)
const std::vector< std::reference_wrapper< Module > > & getLLVMModules() const
LLVMInst2SVFInstMap LLVMInst2SVFInst
SVFModule * svfModule
Borrowed from singleton SVFModule::svfModule.
std::unique_ptr< LLVMContext > owned_ctx
LLVMConst2SVFConstMap LLVMConst2SVFConst
void createSVFDataStructure()
SVFFunction * getSVFFunction(const Function *fun) const
StInfo * collectSimpleTypeInfo(const Type *T)
Collect simple type (non-aggregate) info.
SymbolTableInfo * symInfo
void addArgumentMap(const Argument *arg, SVFArgument *svfArg)
void addOtherConstantMap(const Constant *cons, SVFConstant *svfcons)
SVFType * getSVFType(const Type *T)
Get or create SVFType and typeinfo.
const Type * getLLVMType(const SVFType *T) const
Get LLVM Type.
bool hasICFGNode(const Instruction *inst)
ICFGNode * getICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
SVFConstant * getOtherSVFConstant(const Constant *oc)
CallICFGNode * getCallICFGNode(const Instruction *cs)
get a call node
Fun2AnnoMap ExtFun2Annotations
Record annotations of function in extapi.bc.
void setValueAttr(const Value *val, SVFValue *value)
void addGlobalValueMap(const GlobalValue *glob, SVFGlobalValue *svfglob)
SVFValue2LLVMValueMap SVFValue2LLVMValue
RetICFGNode * getRetICFGNode(const Instruction *cs)
get a return node
void prePassSchedule()
Invoke llvm passes to modify module.
void initDomTree(SVFFunction *func, const Function *f)
StInfo * collectStructInfo(const StructType *structTy, u32_t &numFields)
Collect the struct info and set the number of fields after flattening.
Module * getMainLLVMModule() const
SVFBaseNode2LLVMValueMap SVFBaseNode2LLVMValue
StInfo * collectArrayInfo(const ArrayType *T)
Collect the array info.
void buildGlobalDefToRepMap()
SVFType * addSVFTypeInfo(const Type *t)
Create SVFTypes.
SVFBasicBlock * getSVFBasicBlock(const BasicBlock *bb) const
void addFunctionMap(const Function *func, SVFFunction *svfFunc)
FunctionSetType ExtFuncsVec
Record some "sse_" function declarations used in other ext function definition, e....
CallICFGNode * getCallBlock(const Instruction *cs)
Get/Add a call node.
LLVMContext & getContext() const
LLVMValue2SVFOtherValueMap LLVMValue2SVFOtherValue
IntraICFGNode * getIntraICFGNode(const Instruction *inst)
get a intra node
std::vector< std::reference_wrapper< Module > > modules
static LLVMModuleSet * getLLVMModuleSet()
SVFArgument * getSVFArgument(const Argument *arg) const
Map< std::string, std::vector< std::string > > Fun2AnnoMap
u32_t getModuleNum() const
GlobalDefToRepMapTy GlobalDefToRepMap
Global definition to a rep definition map.
std::vector< std::unique_ptr< Module > > owned_modules
SVFInstruction * getSVFInstruction(const Instruction *inst) const
static SVFModule * buildSVFModule(Module &mod)
IntraICFGNode * getIntraBlock(const Instruction *inst)
Type2TypeInfoMap Type2TypeInfo
void dumpModulesToFile(const std::string &suffix)
void addConstantDataMap(const ConstantData *cd, SVFConstantData *svfcd)
RetICFGNode * getRetBlock(const Instruction *cs)
Get/Add a return node.
void collectExtFunAnnotations(const Module *mod)
ObjTypeInference * getTypeInference()
SVFValue * getSVFValue(const Value *value)
static const Option< bool > SVFMain
static const Option< std::string > Graphtxt
virtual void setSourceLoc(const std::string &sourceCodeInfo)
void addPredBasicBlock(const SVFBasicBlock *pred)
const std::vector< const SVFBasicBlock * > & getSuccessors() const
void addSuccBasicBlock(const SVFBasicBlock *succ)
void setCalledOperand(const SVFValue *v)
void addArgument(const SVFValue *a)
attributes to be set only through Module builders e.g., LLVMModule
void addBasicBlock(const SVFBasicBlock *bb)
a 'single' basic block having no successors and containing return instruction in a function
SVFBasicBlock * exitBlock
all formal arguments of this function
SVFLoopAndDomInfo * getLoopAndDomInfo()
const SVFBasicBlock * back() const
bool hasBasicBlock() const
void setExitBlock(SVFBasicBlock *bb)
void addArgument(SVFArgument *arg)
Map< const SVFBasicBlock *, BBSet > & getDomTreeMap()
const Map< const SVFBasicBlock *, u32_t > & getBBPDomLevel() const
void setReachableBBs(BBList &bbs)
const Map< const SVFBasicBlock *, BBSet > & getPostDomTreeMap() const
Set< const SVFBasicBlock * > BBSet
const Map< const SVFBasicBlock *, BBSet > & getDomFrontierMap() const
const Map< const SVFBasicBlock *, const SVFBasicBlock * > & getBB2PIdom() const
void addToBB2LoopMap(const SVFBasicBlock *bb, const SVFBasicBlock *loopBB)
void addGlobalSet(SVFGlobalValue *glob)
static bool pagReadFromTXT()
void addOtherValue(SVFOtherValue *ov)
static void setPagFromTXT(const std::string &txt)
void addFunctionSet(SVFFunction *svfFunc)
void addAliasSet(SVFGlobalValue *alias)
static SVFModule * getSVFModule()
void setModuleIdentifier(const std::string &moduleIdentifier)
void addConstant(SVFConstant *cd)
static double timeOfBuildingLLVMModule
static double getClk(bool mark=false)
static double timeOfBuildingSymbolTable
static SVFType * svfPtrTy
ptr type
static SVFType * svfI8Ty
8-bit int type
void setTypeInfo(StInfo *ti)
virtual void setSourceLoc(const std::string &sourceCodeInfo)
void setName(const std::string &n)
void setPtrInUncalledFunction()
void setConstDataOrAggData()
std::vector< const SVFType * > & getFlattenElementTypes()
void setNumOfFieldsAndElems(u32_t nf, u32_t ne)
Set number of fields and elements of an aggregate.
u32_t getNumOfFlattenElements() const
Return number of elements after flattening (including array elements)
void addFldWithType(u32_t fldIdx, const SVFType *type, u32_t elemIdx)
Add field index and element index and their corresponding type.
std::vector< const SVFType * > & getFlattenFieldTypes()
u32_t getNumOfFlattenFields() const
Return the number of fields after flattening (ignoring array elements)
void buildMemModel(SVFModule *svfModule)
Start building memory model.
const SVFType * maxStruct
The struct type with the most fields.
void addStInfo(StInfo *stInfo)
void addTypeInfo(const SVFType *ty)
u32_t maxStSize
The number of fields in max_struct.
bool isIntrinsicInst(const Instruction *inst)
Return true if it is an intrinsic instruction.
bool isPtrInUncalledFunction(const Value *value)
Return true if this is value in a dead function (function without any caller)
bool isUncalledFunction(const Function *fun)
whether this is a function without any possible caller?
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 isCallSite(const Instruction *inst)
Whether an instruction is a call or invoke instruction.
bool functionDoesNotRet(const Function *fun)
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 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.
bool basicBlockHasRetInst(const BasicBlock *bb)
Return true if the function has a return instruction.
bool isIRFile(const std::string &filename)
Check whether a file is an LLVM IR file.
std::string restoreFuncName(std::string funcName)
bool isNonInstricCallSite(const Instruction *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
bool isExtCall(const SVFFunction *fun)
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
std::ostream & errs()
Overwrite llvm::errs()
std::ostream & outs()
Overwrite llvm::outs()
std::string getFunNameOfVCallSite(const CallBase *cs)
s32_t getVCallIdx(const CallBase *cs)
const Value * getVCallVtblPtr(const CallBase *cs)
bool isVirtualCallSite(const CallBase *cs)
llvm::DataLayout DataLayout
llvm::GlobalVariable GlobalVariable
llvm::GlobalAlias GlobalAlias
llvm::ArrayType ArrayType
llvm::raw_fd_ostream raw_fd_ostream
LLVM outputs.
llvm::BasicBlock BasicBlock
llvm::inst_iterator inst_iterator
llvm::ConstantStruct ConstantStruct
llvm::StructType StructType
LLVM types.
llvm::succ_const_iterator succ_const_iterator
LLVM Iterators.
llvm::IntegerType IntegerType
std::set< Key, Compare, Allocator > OrderedSet
llvm::ConstantArray ConstantArray
llvm::const_pred_iterator const_pred_iterator
llvm::GlobalValue GlobalValue
llvm::FunctionType FunctionType
llvm::ConstantData ConstantData
llvm::Instruction Instruction
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
llvm::DomTreeNode DomTreeNode
llvm::SMDiagnostic SMDiagnostic
llvm::ConstantDataSequential ConstantDataSequential
llvm::Value Value
LLVM Basic classes.
llvm::ConstantExpr ConstantExpr
llvm::IRBuilder IRBuilder
llvm::GlobalIFunc GlobalIFunc
llvm::PostDominatorTree PostDominatorTree
llvm::DominanceFrontier DominanceFrontier
llvm::Loop Loop
LLVM Loop.
llvm::ConstantFP ConstantFP
llvm::ConstantInt ConstantInt
llvm::DominatorTree DominatorTree
LLVM Dominators.
IntervalValue operator>(const IntervalValue &lhs, const IntervalValue &rhs)
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set