diff --git a/.gitignore b/.gitignore index a3e4c39..c65d128 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ build/* test/* +CMakeFiles +cmake_install.cmake +CMakeCache.txt +Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index 47e64e9..d6becd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.4.3) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "-Wall -fno-rtti") find_package(LLVM REQUIRED CONFIG) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0ac11c6..205201f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,2 +1,5 @@ add_library(HeatCFGPrinter MODULE HeatCFGPrinter.cpp HeatUtils.cpp) add_library(HeatCallPrinter MODULE HeatCallPrinter.cpp HeatUtils.cpp) + +target_link_libraries(HeatCFGPrinter LLVM) +target_link_libraries(HeatCallPrinter LLVM) diff --git a/src/HeatCFGPrinter.cpp b/src/HeatCFGPrinter.cpp index 38a0a45..4e8dbc5 100644 --- a/src/HeatCFGPrinter.cpp +++ b/src/HeatCFGPrinter.cpp @@ -25,6 +25,7 @@ #include "llvm/Analysis/CFGPrinter.h" #include "llvm/IR/Function.h" #include "llvm/IR/Module.h" +#include "llvm/IR/CFG.h" #include "llvm/Pass.h" #include "llvm/Support/DOTGraphTraits.h" #include "llvm/Support/GraphWriter.h" @@ -176,7 +177,7 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits { } static std::string getEdgeSourceLabel(const BasicBlock *Node, - succ_const_iterator I) { + const_succ_iterator I) { // Label source of conditional branches with "T" or "F" if (const BranchInst *BI = dyn_cast(Node->getTerminator())) if (BI->isConditional()) @@ -198,13 +199,13 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits { } /// Display the raw branch weights from PGO. - std::string getEdgeAttributes(const BasicBlock *Node, succ_const_iterator I, + std::string getEdgeAttributes(const BasicBlock *Node, const_succ_iterator I, HeatCFGInfo *Graph) { if (NoEdgeWeight) return ""; - const TerminatorInst *TI = Node->getTerminator(); + const Instruction *TI = Node->getTerminator(); if (TI->getNumSuccessors() == 1) return ""; @@ -278,7 +279,7 @@ static void writeHeatCFGToDotFile(Function &F, BlockFrequencyInfo *BFI, errs() << "Writing '" << Filename << "'..."; std::error_code EC; - raw_fd_ostream File(Filename, EC, sys::fs::F_Text); + raw_fd_ostream File(Filename, EC, sys::fs::OF_Text); HeatCFGInfo heatCFGInfo(&F,BFI,maxFreq,useHeuristic); diff --git a/src/HeatCallPrinter.cpp b/src/HeatCallPrinter.cpp index 97aa1d2..7cd45f5 100644 --- a/src/HeatCallPrinter.cpp +++ b/src/HeatCallPrinter.cpp @@ -83,7 +83,7 @@ class HeatCallGraphInfo { continue; uint64_t localMaxFreq = 0; if (UseCallCounter) { - Optional< uint64_t > freq = F.getEntryCount(); + Optional< uint64_t > freq = F.getEntryCount().getCount(); if (freq.hasValue()) localMaxFreq = freq.getValue(); } else { @@ -165,7 +165,7 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits { std::string(Graph->getModule()->getModuleIdentifier()); } - static bool isNodeHidden(const CallGraphNode *Node) { + static bool isNodeHidden(const CallGraphNode *Node, const HeatCallGraphInfo *G) { if (FullCallGraph) return false; @@ -184,7 +184,7 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits { return "external callee"; if (Function *Func = Node->getFunction()) - return Func->getName(); + return Func->getName().str(); return "external node"; } @@ -257,7 +257,7 @@ bool HeatCallGraphDOTPrinterPass::runOnModule(Module &M) { errs() << "Writing '" << Filename << "'..."; std::error_code EC; - raw_fd_ostream File(Filename, EC, sys::fs::F_Text); + raw_fd_ostream File(Filename, EC, sys::fs::OF_Text); CallGraph CG(M); HeatCallGraphInfo heatCFGInfo(&M,&CG,LookupBFI); diff --git a/src/HeatUtils.cpp b/src/HeatUtils.cpp index 42147c4..71d9ae0 100644 --- a/src/HeatUtils.cpp +++ b/src/HeatUtils.cpp @@ -37,11 +37,12 @@ uint64_t getBlockFreq(const BasicBlock *BB, BlockFrequencyInfo *BFI, } uint64_t getNumOfCalls(Function &callerFunction, Function &calledFunction, - function_ref LookupBFI){ + function_ref LookupBFI, + bool useHeuristic){ auto *BFI = LookupBFI(callerFunction); uint64_t counter = 0; for (BasicBlock &BB : callerFunction) { - uint64_t freq = getBlockFreq(&BB,BFI); + uint64_t freq = getBlockFreq(&BB,BFI,useHeuristic); for (Instruction &I : BB) { if (CallInst *Call = dyn_cast(&I)) { if (Call->getCalledFunction()==(&calledFunction))