10000 Replace ExAPI.json with extapi.c (extapi.c explaination wiki: https://github.com/SVF-tools/SVF/wiki/Handling-External-APIs-with-extapi.c) by shuangxiangkan · Pull Request #1165 · SVF-tools/SVF · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Replace ExAPI.json with extapi.c (extapi.c explaination wiki: https://github.com/SVF-tools/SVF/wiki/Handling-External-APIs-with-extapi.c) #1165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .config.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define CONFIG_H_IN

#define PROJECT_PATH "@CMAKE_CURRENT_SOURCE_DIR@"
#define EXTAPI_PATH PROJECT_PATH "/@CMAKE_BUILD_TYPE@-build/include/Util"

#endif
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,10 @@ install(
DESTINATION include/svf
FILES_MATCHING
PATTERN "**/*.h")

# Compile extapi.c to extapi.bc
find_path(LLVM_CLANG_DIR NAMES clang PATH_SUFFIXES bin)
add_custom_target(extapi_ir ALL
COMMAND ${LLVM_CLANG_DIR}/clang -w -S -c -Xclang -disable-O0-optnone -fno-discard-value-names -emit-llvm ${PROJECT_SOURCE_DIR}/svf/lib/Util/extapi.c -o ${PROJECT_BINARY_DIR}/include/Util/extapi.bc
DEPENDS ${PROJECT_SOURCE_DIR}/svf/lib/Util/extapi.c
)
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function build_llvm_from_source {
mkdir llvm-build
cd llvm-build
# /*/ is a dirty hack to get llvm-project-llvmorg-version...
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$SVFHOME/$LLVMHome" ../llvm-source/*/llvm
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$SVFHOME/$LLVMHome" -DLLVM_ENABLE_PROJECTS=clang ../llvm-source/*/llvm
cmake --build . -j ${jobs}
cmake --install .

Expand Down
17 changes: 17 additions & 0 deletions svf-llvm/include/SVF-LLVM/LLVMModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "Util/CppUtil.h"
#include "SVFIR/SVFValue.h"
#include "SVFIR/SVFModule.h"
#include "Util/Options.h"

namespace SVF
{
Expand Down Expand Up @@ -74,6 +75,8 @@ class LLVMModuleSet
FunDeclToDefMapTy FunDeclToDefMap;
/// Function definition to function declaration map
FunDefToDeclsMapTy FunDefToDeclsMap;
/// Record some "sse_" function declarations used in other ext function definition, e.g., svf_ext_foo(), and svf_ext_foo() used in app functions
FunctionSetType ExtFuncsVec;
/// Global definition to a rep definition map
GlobalDefToRepMapTy GlobalDefToRepMap;

Expand Down Expand Up @@ -233,6 +236,20 @@ class LLVMModuleSet

SVFOtherValue* getSVFOtherValue(const Value* ov);

/// Remove unused function in extapi.bc module
bool isUsedExtFunction(Function* func)
{
/// if this function func defined in extapi.bc but never used in application code (without any corresponding declared functions).
if (func->getParent()->getName().str() == Options::ExtAPIInput()
&& func->getName().str() != "svf__main"
&& FunDefToDeclsMap.find(func) == FunDefToDeclsMap.end()
&& std::find(ExtFuncsVec.begin(), ExtFuncsVec.end(), func) == ExtFuncsVec.end())
{
return true;
}
return false;
}

/// Get the corresponding Function based on its name
inline const SVFFunction* getSVFFunction(const std::string& name)
{
Expand Down
15 changes: 14 additions & 1 deletion svf-llvm/include/SVF-LLVM/LLVMUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "SVF-LLVM/BasicTypes.h"
#include "SVF-LLVM/LLVMModule.h"
#include "SVFIR/SVFValue.h"
#include "Util/ExtAPI.h"
#include "Util/ThreadAPI.h"

namespace SVF
Expand Down Expand Up @@ -373,6 +372,20 @@ const std::string getSourceLocOfFunction(const Function* F);
bool isIntrinsicInst(const Instruction* inst);
bool isIntrinsicFun(const Function* func);

/// Get all called funcions in a parent function
std::vector<const Function *> getCalledFunctions(const Function *F);
std::vector<std::string> getFunAnnotations(const Function* fun);
void removeFunAnnotations(std::vector<Function*>& removedFuncList);

inline void removeUnusedFuncsAndAnnotations(std::vector<Function*> removedFuncList)
{
/// Remove unused function annotations in extapi.bc
LLVMUtil::removeFunAnnotations(removedFuncList);
/// Remove unused function in extapi.bc
for (Function* func : removedFuncList)
func->eraseFromParent();
}

/// Get the corresponding Function based on its name
inline const SVFFunction* getFunction(const std::string& name)
{
Expand Down
19 changes: 5 additions & 14 deletions svf-llvm/include/SVF-LLVM/SVFIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#define PAGBUILDER_H_

#include "SVFIR/SVFIR.h"
#include "Util/ExtAPI.h"
#include "SVF-LLVM/BasicTypes.h"
#include "SVF-LLVM/ICFGBuilder.h"
#include "SVF-LLVM/LLVMModule.h"
#include "SVF-LLVM/LLVMUtil.h"

namespace SVF
{
Expand Down Expand Up @@ -232,18 +232,9 @@ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>

/// Handle external call
//@{
virtual SVFCallInst* addSVFExtCallInst(const SVFCallInst* svfInst, SVFBasicBlock* svfBB, const SVFFunction* svfCaller, const SVFFunction* svfCallee);
virtual void addSVFExtRetInst(SVFCallInst* svfCall, SVFBasicBlock* svfBB, SVFFunction* svfCaller);
virtual SVFInstruction* addSVFExtInst(const std::string& instName, const SVFCallInst* svfInst, SVFBasicBlock* svfBB, SVF::ExtAPI::OperationType opType, const SVFType* svfType);
virtual void extFuncAtomaticOperation(ExtAPI::Operand& atomicOp, const SVFCallInst* svfInst);
virtual SVFBasicBlock* extFuncInitialization(const SVFCallInst* svfInst, SVFFunction* svfCaller);
virtual void handleExtCallStat(ExtAPI::ExtFunctionOps &extFunctionOps, const SVFCallInst* svfInst);
virtual NodeID getExtID(ExtAPI::OperationType operationType, const std::string &s, const SVFCallInst* svfCall);
virtual void parseAtomaticOp(SVF::ExtAPI::Operand &atomaticOp, const SVFCallInst* svfCall, std::map<std::string, NodeID> &nodeIDMap);
virtual void parseExtFunctionOps(ExtAPI::ExtFunctionOps &extFunctionOps, const SVFCallInst* svfCall);
virtual void preProcessExtCall(CallBase* cs);
virtual void handleExtCall(const SVFInstruction* svfInst, const SVFFunction* svfCallee);
void addComplexConsForExt(const SVFValue* D, const SVFValue* S, const SVFValue* sz);
virtual const Type *getBaseTypeAndFlattenedFields(const Value *V, std::vector<AccessPath> &fields, const Value* szValue);
virtual void addComplexConsForExt(Value *D, Value *S, const Value* sz);
virtual void handleExtCall(const CallBase* cs, const SVFFunction* svfCallee);
//@}

/// Set current basic block in order to keep track of control flow information
Expand Down Expand Up @@ -287,7 +278,7 @@ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
return nullPtr;
}

NodeID getGepValVar(const SVFValue* val, const AccessPath& ap, const SVFType* baseType);
NodeID getGepValVar(const Value* val, const AccessPath& ap, const SVFType* elementType);

void setCurrentBBAndValueForPAGEdge(PAGEdge* edge);

Expand Down
Loading
0