mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-03 00:33:09 +00:00
148e8c9b8b
IRCE eliminates range checks of the form 0 <= A * I + B < Length by splitting a loop's iteration space into three segments in a way that the check is completely redundant in the middle segment. As an example, IRCE will convert len = < known positive > for (i = 0; i < n; i++) { if (0 <= i && i < len) { do_something(); } else { throw_out_of_bounds(); } } to len = < known positive > limit = smin(n, len) // no first segment for (i = 0; i < limit; i++) { if (0 <= i && i < len) { // this check is fully redundant do_something(); } else { throw_out_of_bounds(); } } for (i = limit; i < n; i++) { if (0 <= i && i < len) { do_something(); } else { throw_out_of_bounds(); } } IRCE can deal with multiple range checks in the same loop (it takes the intersection of the ranges that will make each of them redundant individually). Currently IRCE does not do any profitability analysis. That is a TODO. Please note that the status of this pass is *experimental*, and it is not part of any default pass pipeline. Having said that, I will love to get feedback and general input from people interested in trying this out. This pass was originally r226201. It was reverted because it used C++ features not supported by MSVC 2012. Differential Revision: http://reviews.llvm.org/D6693 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226238 91177308-0d34-0410-b5e6-96231b3b80d8
228 lines
6.9 KiB
C++
228 lines
6.9 KiB
C++
//===-- Scalar.cpp --------------------------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements common infrastructure for libLLVMScalarOpts.a, which
|
|
// implements several scalar transformations over the LLVM intermediate
|
|
// representation, including the C bindings for that library.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
#include "llvm-c/Initialization.h"
|
|
#include "llvm-c/Transforms/Scalar.h"
|
|
#include "llvm/Analysis/Passes.h"
|
|
#include "llvm/IR/DataLayout.h"
|
|
#include "llvm/IR/Verifier.h"
|
|
#include "llvm/InitializePasses.h"
|
|
#include "llvm/PassManager.h"
|
|
|
|
using namespace llvm;
|
|
|
|
/// initializeScalarOptsPasses - Initialize all passes linked into the
|
|
/// ScalarOpts library.
|
|
void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
|
initializeADCEPass(Registry);
|
|
initializeAlignmentFromAssumptionsPass(Registry);
|
|
initializeSampleProfileLoaderPass(Registry);
|
|
initializeConstantHoistingPass(Registry);
|
|
initializeConstantPropagationPass(Registry);
|
|
initializeCorrelatedValuePropagationPass(Registry);
|
|
initializeDCEPass(Registry);
|
|
initializeDeadInstEliminationPass(Registry);
|
|
initializeScalarizerPass(Registry);
|
|
initializeDSEPass(Registry);
|
|
initializeGVNPass(Registry);
|
|
initializeEarlyCSEPass(Registry);
|
|
initializeFlattenCFGPassPass(Registry);
|
|
initializeInductiveRangeCheckEliminationPass(Registry);
|
|
initializeIndVarSimplifyPass(Registry);
|
|
initializeJumpThreadingPass(Registry);
|
|
initializeLICMPass(Registry);
|
|
initializeLoopDeletionPass(Registry);
|
|
initializeLoopInstSimplifyPass(Registry);
|
|
initializeLoopRotatePass(Registry);
|
|
initializeLoopStrengthReducePass(Registry);
|
|
initializeLoopRerollPass(Registry);
|
|
initializeLoopUnrollPass(Registry);
|
|
initializeLoopUnswitchPass(Registry);
|
|
initializeLoopIdiomRecognizePass(Registry);
|
|
initializeLowerAtomicPass(Registry);
|
|
initializeLowerExpectIntrinsicPass(Registry);
|
|
initializeMemCpyOptPass(Registry);
|
|
initializeMergedLoadStoreMotionPass(Registry);
|
|
initializePartiallyInlineLibCallsPass(Registry);
|
|
initializeReassociatePass(Registry);
|
|
initializeRegToMemPass(Registry);
|
|
initializeSCCPPass(Registry);
|
|
initializeIPSCCPPass(Registry);
|
|
initializeSROAPass(Registry);
|
|
initializeSROA_DTPass(Registry);
|
|
initializeSROA_SSAUpPass(Registry);
|
|
initializeCFGSimplifyPassPass(Registry);
|
|
initializeStructurizeCFGPass(Registry);
|
|
initializeSinkingPass(Registry);
|
|
initializeTailCallElimPass(Registry);
|
|
initializeSeparateConstOffsetFromGEPPass(Registry);
|
|
initializeLoadCombinePass(Registry);
|
|
}
|
|
|
|
void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
|
|
initializeScalarOpts(*unwrap(R));
|
|
}
|
|
|
|
void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createAggressiveDCEPass());
|
|
}
|
|
|
|
void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createAlignmentFromAssumptionsPass());
|
|
}
|
|
|
|
void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createCFGSimplificationPass());
|
|
}
|
|
|
|
void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createDeadStoreEliminationPass());
|
|
}
|
|
|
|
void LLVMAddScalarizerPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createScalarizerPass());
|
|
}
|
|
|
|
void LLVMAddGVNPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createGVNPass());
|
|
}
|
|
|
|
void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createMergedLoadStoreMotionPass());
|
|
}
|
|
|
|
void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createIndVarSimplifyPass());
|
|
}
|
|
|
|
void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createInstructionCombiningPass());
|
|
}
|
|
|
|
void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createJumpThreadingPass());
|
|
}
|
|
|
|
void LLVMAddLICMPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLICMPass());
|
|
}
|
|
|
|
void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLoopDeletionPass());
|
|
}
|
|
|
|
void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLoopIdiomPass());
|
|
}
|
|
|
|
void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLoopRotatePass());
|
|
}
|
|
|
|
void LLVMAddLoopRerollPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLoopRerollPass());
|
|
}
|
|
|
|
void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLoopUnrollPass());
|
|
}
|
|
|
|
void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLoopUnswitchPass());
|
|
}
|
|
|
|
void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createMemCpyOptPass());
|
|
}
|
|
|
|
void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createPartiallyInlineLibCallsPass());
|
|
}
|
|
|
|
void LLVMAddLowerSwitchPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLowerSwitchPass());
|
|
}
|
|
|
|
void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createPromoteMemoryToRegisterPass());
|
|
}
|
|
|
|
void LLVMAddReassociatePass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createReassociatePass());
|
|
}
|
|
|
|
void LLVMAddSCCPPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createSCCPPass());
|
|
}
|
|
|
|
void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createScalarReplAggregatesPass());
|
|
}
|
|
|
|
void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createScalarReplAggregatesPass(-1, false));
|
|
}
|
|
|
|
void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,
|
|
int Threshold) {
|
|
unwrap(PM)->add(createScalarReplAggregatesPass(Threshold));
|
|
}
|
|
|
|
void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM) {
|
|
// NOTE: The simplify-libcalls pass has been removed.
|
|
}
|
|
|
|
void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createTailCallEliminationPass());
|
|
}
|
|
|
|
void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createConstantPropagationPass());
|
|
}
|
|
|
|
void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createDemoteRegisterToMemoryPass());
|
|
}
|
|
|
|
void LLVMAddVerifierPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createVerifierPass());
|
|
// FIXME: should this also add createDebugInfoVerifierPass()?
|
|
}
|
|
|
|
void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createCorrelatedValuePropagationPass());
|
|
}
|
|
|
|
void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createEarlyCSEPass());
|
|
}
|
|
|
|
void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createTypeBasedAliasAnalysisPass());
|
|
}
|
|
|
|
void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createScopedNoAliasAAPass());
|
|
}
|
|
|
|
void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createBasicAliasAnalysisPass());
|
|
}
|
|
|
|
void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLowerExpectIntrinsicPass());
|
|
}
|