Skip to content
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

Compiles #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
build/*
test/*
CMakeFiles
cmake_install.cmake
CMakeCache.txt
Makefile
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 5 additions & 4 deletions src/HeatCFGPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -176,7 +177,7 @@ struct DOTGraphTraits<HeatCFGInfo *> : 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<BranchInst>(Node->getTerminator()))
if (BI->isConditional())
Expand All @@ -198,13 +199,13 @@ struct DOTGraphTraits<HeatCFGInfo *> : 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 "";

Expand Down Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions src/HeatCallPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -165,7 +165,7 @@ struct DOTGraphTraits<HeatCallGraphInfo *> : 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;

Expand All @@ -184,7 +184,7 @@ struct DOTGraphTraits<HeatCallGraphInfo *> : public DefaultDOTGraphTraits {
return "external callee";

if (Function *Func = Node->getFunction())
return Func->getName();
return Func->getName().str();

return "external node";
}
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/HeatUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ uint64_t getBlockFreq(const BasicBlock *BB, BlockFrequencyInfo *BFI,
}

uint64_t getNumOfCalls(Function &callerFunction, Function &calledFunction,
function_ref<BlockFrequencyInfo *(Function &)> LookupBFI){
function_ref<BlockFrequencyInfo *(Function &)> 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<CallInst>(&I)) {
if (Call->getCalledFunction()==(&calledFunction))
Expand Down