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

Add statistics/verification to cpufeatures and julia-licm #44592

Merged
merged 1 commit into from
Apr 5, 2022
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
14 changes: 11 additions & 3 deletions src/llvm-cpufeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
#include "llvm-version.h"
#include "passes.h"

#include <llvm/ADT/Statistic.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/PassManager.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Support/Debug.h>

Expand All @@ -31,6 +33,9 @@

using namespace llvm;

STATISTIC(LoweredWithFMA, "Number of have_fma's that were lowered to true");
STATISTIC(LoweredWithoutFMA, "Number of have_fma's that were lowered to false");

extern JuliaOJIT *jl_ExecutionEngine;

// whether this platform unconditionally (i.e. without needing multiversioning) supports FMA
Expand Down Expand Up @@ -75,11 +80,13 @@ bool have_fma(Function &intr, Function &caller) {
}

void lowerHaveFMA(Function &intr, Function &caller, CallInst *I) {
if (have_fma(intr, caller))
if (have_fma(intr, caller)) {
++LoweredWithFMA;
I->replaceAllUsesWith(ConstantInt::get(I->getType(), 1));
else
} else {
++LoweredWithoutFMA;
I->replaceAllUsesWith(ConstantInt::get(I->getType(), 0));

}
return;
}

Expand All @@ -104,6 +111,7 @@ bool lowerCPUFeatures(Module &M)
for (auto I: Materialized) {
I->eraseFromParent();
}
assert(!verifyModule(M));
return true;
} else {
return false;
Expand Down
14 changes: 14 additions & 0 deletions src/llvm-julia-licm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include "llvm-version.h"
#include "passes.h"

#include <llvm/ADT/Statistic.h>
#include <llvm/Analysis/LoopInfo.h>
#include <llvm/Analysis/LoopPass.h>
#include "llvm/Analysis/LoopIterator.h"
#include <llvm/IR/Dominators.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Transforms/Utils/LoopUtils.h>
#include <llvm/Analysis/ValueTracking.h>

Expand All @@ -20,6 +22,12 @@

using namespace llvm;

STATISTIC(HoistedPreserveBegin, "Number of gc_preserve_begin instructions hoisted out of a loop");
STATISTIC(SunkPreserveEnd, "Number of gc_preserve_end instructions sunk out of a loop");
STATISTIC(ErasedPreserveEnd, "Number of gc_preserve_end instructions removed from nonterminating loops");
STATISTIC(HoistedWriteBarrier, "Number of write barriers hoisted out of a loop");
STATISTIC(HoistedAllocation, "Number of allocations hoisted out of a loop");

/*
* Julia LICM pass.
* This takes care of some julia intrinsics that is safe to move around/out of loops but
Expand Down Expand Up @@ -114,6 +122,7 @@ struct JuliaLICM : public JuliaPassContext {
}
if (!canhoist)
continue;
++HoistedPreserveBegin;
call->moveBefore(preheader->getTerminator());
changed = true;
}
Expand All @@ -124,9 +133,11 @@ struct JuliaLICM : public JuliaPassContext {
changed = true;
auto exit_pts = get_exit_pts();
if (exit_pts.empty()) {
++ErasedPreserveEnd;
call->eraseFromParent();
continue;
}
++SunkPreserveEnd;
call->moveBefore(exit_pts[0]);
for (unsigned i = 1; i < exit_pts.size(); i++) {
// Clone exit
Expand All @@ -143,6 +154,7 @@ struct JuliaLICM : public JuliaPassContext {
}
}
if (valid) {
++HoistedWriteBarrier;
call->moveBefore(preheader->getTerminator());
changed = true;
}
Expand All @@ -168,12 +180,14 @@ struct JuliaLICM : public JuliaPassContext {
continue;
}
if (valid) {
++HoistedAllocation;
call->moveBefore(preheader->getTerminator());
changed = true;
}
}
}
}
assert(!verifyFunction(*L->getHeader()->getParent()));
return changed;
}
};
Expand Down