mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
Add an Assumption-Tracking Pass
This adds an immutable pass, AssumptionTracker, which keeps a cache of @llvm.assume call instructions within a module. It uses callback value handles to keep stale functions and intrinsics out of the map, and it relies on any code that creates new @llvm.assume calls to notify it of the new instructions. The benefit is that code needing to find @llvm.assume intrinsics can do so directly, without scanning the function, thus allowing the cost of @llvm.assume handling to be negligible when none are present. The current design is intended to be lightweight. We don't keep track of anything until we need a list of assumptions in some function. The first time this happens, we scan the function. After that, we add/remove @llvm.assume calls from the cache in response to registration calls and ValueHandle callbacks. There are no new direct test cases for this pass, but because it calls it validation function upon module finalization, we'll pick up detectable inconsistencies from the other tests that touch @llvm.assume calls. This pass will be used by follow-up commits that make use of @llvm.assume. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217334 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Analysis/AssumptionTracker.h"
|
||||
#include "llvm/Analysis/CodeMetrics.h"
|
||||
#include "llvm/Analysis/LoopPass.h"
|
||||
#include "llvm/Analysis/ScalarEvolution.h"
|
||||
@@ -102,6 +103,7 @@ namespace {
|
||||
/// loop preheaders be inserted into the CFG...
|
||||
///
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<AssumptionTracker>();
|
||||
AU.addRequired<LoopInfo>();
|
||||
AU.addPreserved<LoopInfo>();
|
||||
AU.addRequiredID(LoopSimplifyID);
|
||||
@@ -182,6 +184,7 @@ namespace {
|
||||
char LoopUnroll::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(LoopUnroll, "loop-unroll", "Unroll loops", false, false)
|
||||
INITIALIZE_AG_DEPENDENCY(TargetTransformInfo)
|
||||
INITIALIZE_PASS_DEPENDENCY(AssumptionTracker)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
||||
INITIALIZE_PASS_DEPENDENCY(LCSSA)
|
||||
@@ -351,6 +354,7 @@ bool LoopUnroll::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||
LoopInfo *LI = &getAnalysis<LoopInfo>();
|
||||
ScalarEvolution *SE = &getAnalysis<ScalarEvolution>();
|
||||
const TargetTransformInfo &TTI = getAnalysis<TargetTransformInfo>();
|
||||
AssumptionTracker *AT = &getAnalysis<AssumptionTracker>();
|
||||
|
||||
BasicBlock *Header = L->getHeader();
|
||||
DEBUG(dbgs() << "Loop Unroll: F[" << Header->getParent()->getName()
|
||||
@@ -493,7 +497,8 @@ bool LoopUnroll::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||
}
|
||||
|
||||
// Unroll the loop.
|
||||
if (!UnrollLoop(L, Count, TripCount, AllowRuntime, TripMultiple, LI, this, &LPM))
|
||||
if (!UnrollLoop(L, Count, TripCount, AllowRuntime, TripMultiple, LI, this,
|
||||
&LPM, AT))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/Analysis/AssumptionTracker.h"
|
||||
#include "llvm/Analysis/CodeMetrics.h"
|
||||
#include "llvm/Analysis/InstructionSimplify.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
@@ -126,6 +127,7 @@ namespace {
|
||||
class LoopUnswitch : public LoopPass {
|
||||
LoopInfo *LI; // Loop information
|
||||
LPPassManager *LPM;
|
||||
AssumptionTracker *AT;
|
||||
|
||||
// LoopProcessWorklist - Used to check if second loop needs processing
|
||||
// after RewriteLoopBodyWithConditionConstant rewrites first loop.
|
||||
@@ -164,6 +166,7 @@ namespace {
|
||||
/// loop preheaders be inserted into the CFG.
|
||||
///
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<AssumptionTracker>();
|
||||
AU.addRequiredID(LoopSimplifyID);
|
||||
AU.addPreservedID(LoopSimplifyID);
|
||||
AU.addRequired<LoopInfo>();
|
||||
@@ -326,6 +329,7 @@ char LoopUnswitch::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(LoopUnswitch, "loop-unswitch", "Unswitch loops",
|
||||
false, false)
|
||||
INITIALIZE_AG_DEPENDENCY(TargetTransformInfo)
|
||||
INITIALIZE_PASS_DEPENDENCY(AssumptionTracker)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
|
||||
INITIALIZE_PASS_DEPENDENCY(LCSSA)
|
||||
@@ -376,6 +380,7 @@ bool LoopUnswitch::runOnLoop(Loop *L, LPPassManager &LPM_Ref) {
|
||||
if (skipOptnoneFunction(L))
|
||||
return false;
|
||||
|
||||
AT = &getAnalysis<AssumptionTracker>();
|
||||
LI = &getAnalysis<LoopInfo>();
|
||||
LPM = &LPM_Ref;
|
||||
DominatorTreeWrapperPass *DTWP =
|
||||
@@ -823,6 +828,10 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
|
||||
F->getBasicBlockList().splice(NewPreheader, F->getBasicBlockList(),
|
||||
NewBlocks[0], F->end());
|
||||
|
||||
// FIXME: We could register any cloned assumptions instead of clearing the
|
||||
// whole function's cache.
|
||||
AT->forgetCachedAssumptions(F);
|
||||
|
||||
// Now we create the new Loop object for the versioned loop.
|
||||
Loop *NewLoop = CloneLoop(L, L->getParentLoop(), VMap, LI, LPM);
|
||||
|
||||
|
Reference in New Issue
Block a user