
This recommit r317351 after fixing a buildbot failure. Original commit message: Summary: This change add a pass which tries to split a call-site to pass more constrained arguments if its argument is predicated in the control flow so that we can expose better context to the later passes (e.g, inliner, jump threading, or IPA-CP based function cloning, etc.). As of now we support two cases : 1) If a call site is dominated by an OR condition and if any of its arguments are predicated on this OR condition, try to split the condition with more constrained arguments. For example, in the code below, we try to split the call site since we can predicate the argument (ptr) based on the OR condition. Split from : if (!ptr || c) callee(ptr); to : if (!ptr) callee(null ptr) // set the known constant value else if (c) callee(nonnull ptr) // set non-null attribute in the argument 2) We can also split a call-site based on constant incoming values of a PHI For example, from : BB0: %c = icmp eq i32 %i1, %i2 br i1 %c, label %BB2, label %BB1 BB1: br label %BB2 BB2: %p = phi i32 [ 0, %BB0 ], [ 1, %BB1 ] call void @bar(i32 %p) to BB0: %c = icmp eq i32 %i1, %i2 br i1 %c, label %BB2-split0, label %BB1 BB1: br label %BB2-split1 BB2-split0: call void @bar(i32 0) br label %BB2 BB2-split1: call void @bar(i32 1) br label %BB2 BB2: %p = phi i32 [ 0, %BB2-split0 ], [ 1, %BB2-split1 ] llvm-svn: 317362
281 lines
9.1 KiB
C++
281 lines
9.1 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/BasicAliasAnalysis.h"
|
|
#include "llvm/Analysis/Passes.h"
|
|
#include "llvm/Analysis/ScopedNoAliasAA.h"
|
|
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
|
|
#include "llvm/IR/DataLayout.h"
|
|
#include "llvm/IR/LegacyPassManager.h"
|
|
#include "llvm/IR/Verifier.h"
|
|
#include "llvm/InitializePasses.h"
|
|
#include "llvm/Transforms/Scalar/GVN.h"
|
|
#include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
|
|
|
|
using namespace llvm;
|
|
|
|
/// initializeScalarOptsPasses - Initialize all passes linked into the
|
|
/// ScalarOpts library.
|
|
void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
|
initializeADCELegacyPassPass(Registry);
|
|
initializeBDCELegacyPassPass(Registry);
|
|
initializeAlignmentFromAssumptionsPass(Registry);
|
|
initializeCallSiteSplittingLegacyPassPass(Registry);
|
|
initializeConstantHoistingLegacyPassPass(Registry);
|
|
initializeConstantPropagationPass(Registry);
|
|
initializeCorrelatedValuePropagationPass(Registry);
|
|
initializeDCELegacyPassPass(Registry);
|
|
initializeDeadInstEliminationPass(Registry);
|
|
initializeDivRemPairsLegacyPassPass(Registry);
|
|
initializeScalarizerPass(Registry);
|
|
initializeDSELegacyPassPass(Registry);
|
|
initializeGuardWideningLegacyPassPass(Registry);
|
|
initializeGVNLegacyPassPass(Registry);
|
|
initializeNewGVNLegacyPassPass(Registry);
|
|
initializeEarlyCSELegacyPassPass(Registry);
|
|
initializeEarlyCSEMemSSALegacyPassPass(Registry);
|
|
initializeGVNHoistLegacyPassPass(Registry);
|
|
initializeGVNSinkLegacyPassPass(Registry);
|
|
initializeFlattenCFGPassPass(Registry);
|
|
initializeInductiveRangeCheckEliminationPass(Registry);
|
|
initializeIndVarSimplifyLegacyPassPass(Registry);
|
|
initializeInferAddressSpacesPass(Registry);
|
|
initializeJumpThreadingPass(Registry);
|
|
initializeLegacyLICMPassPass(Registry);
|
|
initializeLegacyLoopSinkPassPass(Registry);
|
|
initializeLoopDataPrefetchLegacyPassPass(Registry);
|
|
initializeLoopDeletionLegacyPassPass(Registry);
|
|
initializeLoopAccessLegacyAnalysisPass(Registry);
|
|
initializeLoopInstSimplifyLegacyPassPass(Registry);
|
|
initializeLoopInterchangePass(Registry);
|
|
initializeLoopPredicationLegacyPassPass(Registry);
|
|
initializeLoopRotateLegacyPassPass(Registry);
|
|
initializeLoopStrengthReducePass(Registry);
|
|
initializeLoopRerollPass(Registry);
|
|
initializeLoopUnrollPass(Registry);
|
|
initializeLoopUnswitchPass(Registry);
|
|
initializeLoopVersioningLICMPass(Registry);
|
|
initializeLoopIdiomRecognizeLegacyPassPass(Registry);
|
|
initializeLowerAtomicLegacyPassPass(Registry);
|
|
initializeLowerExpectIntrinsicPass(Registry);
|
|
initializeLowerGuardIntrinsicLegacyPassPass(Registry);
|
|
initializeMemCpyOptLegacyPassPass(Registry);
|
|
initializeMergeICmpsPass(Registry);
|
|
initializeMergedLoadStoreMotionLegacyPassPass(Registry);
|
|
initializeNaryReassociateLegacyPassPass(Registry);
|
|
initializePartiallyInlineLibCallsLegacyPassPass(Registry);
|
|
initializeReassociateLegacyPassPass(Registry);
|
|
initializeRegToMemPass(Registry);
|
|
initializeRewriteStatepointsForGCPass(Registry);
|
|
initializeSCCPLegacyPassPass(Registry);
|
|
initializeIPSCCPLegacyPassPass(Registry);
|
|
initializeSROALegacyPassPass(Registry);
|
|
initializeCFGSimplifyPassPass(Registry);
|
|
initializeStructurizeCFGPass(Registry);
|
|
initializeSimpleLoopUnswitchLegacyPassPass(Registry);
|
|
initializeSinkingLegacyPassPass(Registry);
|
|
initializeTailCallElimPass(Registry);
|
|
initializeSeparateConstOffsetFromGEPPass(Registry);
|
|
initializeSpeculativeExecutionLegacyPassPass(Registry);
|
|
initializeStraightLineStrengthReducePass(Registry);
|
|
initializePlaceBackedgeSafepointsImplPass(Registry);
|
|
initializePlaceSafepointsPass(Registry);
|
|
initializeFloat2IntLegacyPassPass(Registry);
|
|
initializeLoopDistributeLegacyPass(Registry);
|
|
initializeLoopLoadEliminationPass(Registry);
|
|
initializeLoopSimplifyCFGLegacyPassPass(Registry);
|
|
initializeLoopVersioningPassPass(Registry);
|
|
}
|
|
|
|
void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
|
|
initializeScalarOpts(*unwrap(R));
|
|
}
|
|
|
|
void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createAggressiveDCEPass());
|
|
}
|
|
|
|
void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createBitTrackingDCEPass());
|
|
}
|
|
|
|
void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createAlignmentFromAssumptionsPass());
|
|
}
|
|
|
|
void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createCFGSimplificationPass(1, false, false, true));
|
|
}
|
|
|
|
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 LLVMAddNewGVNPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createNewGVNPass());
|
|
}
|
|
|
|
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 LLVMAddLoopSinkPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLoopSinkPass());
|
|
}
|
|
|
|
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 LLVMAddLoopSimplifyCFGPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLoopSimplifyCFGPass());
|
|
}
|
|
|
|
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(createSROAPass());
|
|
}
|
|
|
|
void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createSROAPass());
|
|
}
|
|
|
|
void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,
|
|
int Threshold) {
|
|
unwrap(PM)->add(createSROAPass());
|
|
}
|
|
|
|
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(false/*=UseMemorySSA*/));
|
|
}
|
|
|
|
void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createEarlyCSEPass(true/*=UseMemorySSA*/));
|
|
}
|
|
|
|
void LLVMAddGVNHoistLegacyPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createGVNHoistPass());
|
|
}
|
|
|
|
void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createTypeBasedAAWrapperPass());
|
|
}
|
|
|
|
void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createScopedNoAliasAAWrapperPass());
|
|
}
|
|
|
|
void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createBasicAAWrapperPass());
|
|
}
|
|
|
|
void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM) {
|
|
unwrap(PM)->add(createLowerExpectIntrinsicPass());
|
|
}
|