mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-14 17:57:43 +00:00
![Hal Finkel](/assets/img/avatar_default.png)
This adds a loop rerolling pass: the opposite of (partial) loop unrolling. The transformation aims to take loops like this: for (int i = 0; i < 3200; i += 5) { a[i] += alpha * b[i]; a[i + 1] += alpha * b[i + 1]; a[i + 2] += alpha * b[i + 2]; a[i + 3] += alpha * b[i + 3]; a[i + 4] += alpha * b[i + 4]; } and turn them into this: for (int i = 0; i < 3200; ++i) { a[i] += alpha * b[i]; } and loops like this: for (int i = 0; i < 500; ++i) { x[3*i] = foo(0); x[3*i+1] = foo(0); x[3*i+2] = foo(0); } and turn them into this: for (int i = 0; i < 1500; ++i) { x[i] = foo(0); } There are two motivations for this transformation: 1. Code-size reduction (especially relevant, obviously, when compiling for code size). 2. Providing greater choice to the loop vectorizer (and generic unroller) to choose the unrolling factor (and a better ability to vectorize). The loop vectorizer can take vector lengths and register pressure into account when choosing an unrolling factor, for example, and a pre-unrolled loop limits that choice. This is especially problematic if the manual unrolling was optimized for a machine different from the current target. The current implementation is limited to single basic-block loops only. The rerolling recognition should work regardless of how the loop iterations are intermixed within the loop body (subject to dependency and side-effect constraints), but the significant restriction is that the order of the instructions in each iteration must be identical. This seems sufficient to capture all current use cases. This pass is not currently enabled by default at any optimization level. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194939 91177308-0d34-0410-b5e6-96231b3b80d8
200 lines
6.0 KiB
C++
200 lines
6.0 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/Analysis/Verifier.h"
|
|
#include "llvm/IR/DataLayout.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);
|
|
initializeSampleProfileLoaderPass(Registry);
|
|
initializeCodeGenPreparePass(Registry);
|
|
initializeConstantPropagationPass(Registry);
|
|
initializeCorrelatedValuePropagationPass(Registry);
|
|
initializeDCEPass(Registry);
|
|
initializeDeadInstEliminationPass(Registry);
|
|
initializeDSEPass(Registry);
|
|
initializeGVNPass(Registry);
|
|
initializeEarlyCSEPass(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);
|
|
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);
|
|
}
|
|
|
|
void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
|
|
initializeScalarOpts(*unwrap(R));
|
|
}
|
|
|
|
void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createAggressiveDCEPass());
|
|
}
|
|
|
|
void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createCFGSimplificationPass());
|
|
}
|
|
|
|
void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createDeadStoreEliminationPass());
|
|
}
|
|
|
|
void LLVMAddGVNPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createGVNPass());
|
|
}
|
|
|
|
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 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());
|
|
}
|
|
|
|
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 LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createBasicAliasAnalysisPass());
|
|
}
|
|
|
|
void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLowerExpectIntrinsicPass());
|
|
}
|