[CodeGen] Port ExpandMemCmp
to new pass manager (#74050)
This commit is contained in:
parent
300a55003c
commit
60eca674b1
@ -25,6 +25,7 @@
|
||||
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
|
||||
#include "llvm/CodeGen/CallBrPrepare.h"
|
||||
#include "llvm/CodeGen/DwarfEHPrepare.h"
|
||||
#include "llvm/CodeGen/ExpandMemCmp.h"
|
||||
#include "llvm/CodeGen/ExpandReductions.h"
|
||||
#include "llvm/CodeGen/GCMetadata.h"
|
||||
#include "llvm/CodeGen/IndirectBrExpand.h"
|
||||
@ -628,7 +629,7 @@ void CodeGenPassBuilder<Derived>::addIRPasses(AddIRPass &addPass) const {
|
||||
// target lowering hook.
|
||||
if (!Opt.DisableMergeICmps)
|
||||
addPass(MergeICmpsPass());
|
||||
addPass(ExpandMemCmpPass());
|
||||
addPass(ExpandMemCmpPass(&TM));
|
||||
}
|
||||
|
||||
// Run GC lowering passes for builtin collectors
|
||||
|
29
llvm/include/llvm/CodeGen/ExpandMemCmp.h
Normal file
29
llvm/include/llvm/CodeGen/ExpandMemCmp.h
Normal file
@ -0,0 +1,29 @@
|
||||
//===--- ExpandMemCmp.h - Expand memcmp() to load/stores --------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CODEGEN_EXPANDMEMCMP_H
|
||||
#define LLVM_CODEGEN_EXPANDMEMCMP_H
|
||||
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class TargetMachine;
|
||||
|
||||
class ExpandMemCmpPass : public PassInfoMixin<ExpandMemCmpPass> {
|
||||
const TargetMachine *TM;
|
||||
|
||||
public:
|
||||
explicit ExpandMemCmpPass(const TargetMachine *TM_) : TM(TM_) {}
|
||||
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_CODEGEN_EXPANDMEMCMP_H
|
@ -46,6 +46,7 @@ FUNCTION_PASS("dwarf-eh-prepare", DwarfEHPreparePass, (TM))
|
||||
FUNCTION_PASS("ee-instrument", EntryExitInstrumenterPass, (false))
|
||||
FUNCTION_PASS("expand-large-div-rem", ExpandLargeDivRemPass, ())
|
||||
FUNCTION_PASS("expand-large-fp-convert", ExpandLargeFpConvertPass, ())
|
||||
FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass, (TM))
|
||||
FUNCTION_PASS("expand-reductions", ExpandReductionsPass, ())
|
||||
FUNCTION_PASS("expandvp", ExpandVectorPredicationPass, ())
|
||||
FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass, (TM))
|
||||
@ -130,7 +131,6 @@ MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis,
|
||||
#endif
|
||||
DUMMY_FUNCTION_PASS("atomic-expand", AtomicExpandPass, ())
|
||||
DUMMY_FUNCTION_PASS("codegenprepare", CodeGenPreparePass, ())
|
||||
DUMMY_FUNCTION_PASS("expandmemcmp", ExpandMemCmpPass, ())
|
||||
DUMMY_FUNCTION_PASS("gc-lowering", GCLoweringPass, ())
|
||||
DUMMY_FUNCTION_PASS("shadow-stack-gc-lowering", ShadowStackGCLoweringPass, ())
|
||||
DUMMY_FUNCTION_PASS("stack-protector", StackProtectorPass, ())
|
||||
|
@ -520,7 +520,7 @@ namespace llvm {
|
||||
FunctionPass *createExpandLargeFpConvertPass();
|
||||
|
||||
// This pass expands memcmp() to load/stores.
|
||||
FunctionPass *createExpandMemCmpPass();
|
||||
FunctionPass *createExpandMemCmpLegacyPass();
|
||||
|
||||
/// Creates Break False Dependencies pass. \see BreakFalseDeps.cpp
|
||||
FunctionPass *createBreakFalseDeps();
|
||||
|
@ -103,7 +103,7 @@ void initializeEdgeBundlesPass(PassRegistry&);
|
||||
void initializeEHContGuardCatchretPass(PassRegistry &);
|
||||
void initializeExpandLargeFpConvertLegacyPassPass(PassRegistry&);
|
||||
void initializeExpandLargeDivRemLegacyPassPass(PassRegistry&);
|
||||
void initializeExpandMemCmpPassPass(PassRegistry&);
|
||||
void initializeExpandMemCmpLegacyPassPass(PassRegistry &);
|
||||
void initializeExpandPostRAPass(PassRegistry&);
|
||||
void initializeExpandReductionsPass(PassRegistry&);
|
||||
void initializeExpandVectorPredicationPass(PassRegistry &);
|
||||
|
@ -119,7 +119,7 @@ namespace {
|
||||
(void) llvm::createPostDomTree();
|
||||
(void) llvm::createMergeICmpsLegacyPass();
|
||||
(void) llvm::createExpandLargeDivRemPass();
|
||||
(void) llvm::createExpandMemCmpPass();
|
||||
(void)llvm::createExpandMemCmpLegacyPass();
|
||||
(void) llvm::createExpandVectorPredicationPass();
|
||||
std::string buf;
|
||||
llvm::raw_string_ostream os(buf);
|
||||
|
@ -41,7 +41,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
|
||||
initializeEarlyTailDuplicatePass(Registry);
|
||||
initializeExpandLargeDivRemLegacyPassPass(Registry);
|
||||
initializeExpandLargeFpConvertLegacyPassPass(Registry);
|
||||
initializeExpandMemCmpPassPass(Registry);
|
||||
initializeExpandMemCmpLegacyPassPass(Registry);
|
||||
initializeExpandPostRAPass(Registry);
|
||||
initializeFEntryInserterPass(Registry);
|
||||
initializeFinalizeISelPass(Registry);
|
||||
|
@ -11,6 +11,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/CodeGen/ExpandMemCmp.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/Analysis/ConstantFolding.h"
|
||||
#include "llvm/Analysis/DomTreeUpdater.h"
|
||||
@ -38,7 +39,7 @@ namespace llvm {
|
||||
class TargetLowering;
|
||||
}
|
||||
|
||||
#define DEBUG_TYPE "expandmemcmp"
|
||||
#define DEBUG_TYPE "expand-memcmp"
|
||||
|
||||
STATISTIC(NumMemCmpCalls, "Number of memcmp calls");
|
||||
STATISTIC(NumMemCmpNotConstant, "Number of memcmp calls without constant size");
|
||||
@ -886,12 +887,24 @@ static bool expandMemCmp(CallInst *CI, const TargetTransformInfo *TTI,
|
||||
return true;
|
||||
}
|
||||
|
||||
class ExpandMemCmpPass : public FunctionPass {
|
||||
// Returns true if a change was made.
|
||||
static bool runOnBlock(BasicBlock &BB, const TargetLibraryInfo *TLI,
|
||||
const TargetTransformInfo *TTI, const TargetLowering *TL,
|
||||
const DataLayout &DL, ProfileSummaryInfo *PSI,
|
||||
BlockFrequencyInfo *BFI, DomTreeUpdater *DTU);
|
||||
|
||||
static PreservedAnalyses runImpl(Function &F, const TargetLibraryInfo *TLI,
|
||||
const TargetTransformInfo *TTI,
|
||||
const TargetLowering *TL,
|
||||
ProfileSummaryInfo *PSI,
|
||||
BlockFrequencyInfo *BFI, DominatorTree *DT);
|
||||
|
||||
class ExpandMemCmpLegacyPass : public FunctionPass {
|
||||
public:
|
||||
static char ID;
|
||||
|
||||
ExpandMemCmpPass() : FunctionPass(ID) {
|
||||
initializeExpandMemCmpPassPass(*PassRegistry::getPassRegistry());
|
||||
ExpandMemCmpLegacyPass() : FunctionPass(ID) {
|
||||
initializeExpandMemCmpLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F) override {
|
||||
@ -928,25 +941,13 @@ private:
|
||||
LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
|
||||
FunctionPass::getAnalysisUsage(AU);
|
||||
}
|
||||
|
||||
PreservedAnalyses runImpl(Function &F, const TargetLibraryInfo *TLI,
|
||||
const TargetTransformInfo *TTI,
|
||||
const TargetLowering *TL, ProfileSummaryInfo *PSI,
|
||||
BlockFrequencyInfo *BFI, DominatorTree *DT);
|
||||
// Returns true if a change was made.
|
||||
bool runOnBlock(BasicBlock &BB, const TargetLibraryInfo *TLI,
|
||||
const TargetTransformInfo *TTI, const TargetLowering *TL,
|
||||
const DataLayout &DL, ProfileSummaryInfo *PSI,
|
||||
BlockFrequencyInfo *BFI, DomTreeUpdater *DTU);
|
||||
};
|
||||
|
||||
bool ExpandMemCmpPass::runOnBlock(BasicBlock &BB, const TargetLibraryInfo *TLI,
|
||||
const TargetTransformInfo *TTI,
|
||||
const TargetLowering *TL,
|
||||
const DataLayout &DL, ProfileSummaryInfo *PSI,
|
||||
BlockFrequencyInfo *BFI,
|
||||
DomTreeUpdater *DTU) {
|
||||
for (Instruction& I : BB) {
|
||||
bool runOnBlock(BasicBlock &BB, const TargetLibraryInfo *TLI,
|
||||
const TargetTransformInfo *TTI, const TargetLowering *TL,
|
||||
const DataLayout &DL, ProfileSummaryInfo *PSI,
|
||||
BlockFrequencyInfo *BFI, DomTreeUpdater *DTU) {
|
||||
for (Instruction &I : BB) {
|
||||
CallInst *CI = dyn_cast<CallInst>(&I);
|
||||
if (!CI) {
|
||||
continue;
|
||||
@ -961,8 +962,7 @@ bool ExpandMemCmpPass::runOnBlock(BasicBlock &BB, const TargetLibraryInfo *TLI,
|
||||
return false;
|
||||
}
|
||||
|
||||
PreservedAnalyses
|
||||
ExpandMemCmpPass::runImpl(Function &F, const TargetLibraryInfo *TLI,
|
||||
PreservedAnalyses runImpl(Function &F, const TargetLibraryInfo *TLI,
|
||||
const TargetTransformInfo *TTI,
|
||||
const TargetLowering *TL, ProfileSummaryInfo *PSI,
|
||||
BlockFrequencyInfo *BFI, DominatorTree *DT) {
|
||||
@ -994,17 +994,32 @@ ExpandMemCmpPass::runImpl(Function &F, const TargetLibraryInfo *TLI,
|
||||
|
||||
} // namespace
|
||||
|
||||
char ExpandMemCmpPass::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(ExpandMemCmpPass, "expandmemcmp",
|
||||
PreservedAnalyses ExpandMemCmpPass::run(Function &F,
|
||||
FunctionAnalysisManager &FAM) {
|
||||
const auto *TL = TM->getSubtargetImpl(F)->getTargetLowering();
|
||||
const auto &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
|
||||
const auto &TTI = FAM.getResult<TargetIRAnalysis>(F);
|
||||
auto *PSI = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F)
|
||||
.getCachedResult<ProfileSummaryAnalysis>(*F.getParent());
|
||||
BlockFrequencyInfo *BFI = (PSI && PSI->hasProfileSummary())
|
||||
? &FAM.getResult<BlockFrequencyAnalysis>(F)
|
||||
: nullptr;
|
||||
auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(F);
|
||||
|
||||
return runImpl(F, &TLI, &TTI, TL, PSI, BFI, DT);
|
||||
}
|
||||
|
||||
char ExpandMemCmpLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(ExpandMemCmpLegacyPass, DEBUG_TYPE,
|
||||
"Expand memcmp() to load/stores", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||
INITIALIZE_PASS_END(ExpandMemCmpPass, "expandmemcmp",
|
||||
INITIALIZE_PASS_END(ExpandMemCmpLegacyPass, DEBUG_TYPE,
|
||||
"Expand memcmp() to load/stores", false, false)
|
||||
|
||||
FunctionPass *llvm::createExpandMemCmpPass() {
|
||||
return new ExpandMemCmpPass();
|
||||
FunctionPass *llvm::createExpandMemCmpLegacyPass() {
|
||||
return new ExpandMemCmpLegacyPass();
|
||||
}
|
||||
|
@ -868,7 +868,7 @@ void TargetPassConfig::addIRPasses() {
|
||||
// target lowering hook.
|
||||
if (!DisableMergeICmps)
|
||||
addPass(createMergeICmpsLegacyPass());
|
||||
addPass(createExpandMemCmpPass());
|
||||
addPass(createExpandMemCmpLegacyPass());
|
||||
}
|
||||
|
||||
// Run GC lowering passes for builtin collectors
|
||||
|
@ -76,6 +76,7 @@
|
||||
#include "llvm/CodeGen/DwarfEHPrepare.h"
|
||||
#include "llvm/CodeGen/ExpandLargeDivRem.h"
|
||||
#include "llvm/CodeGen/ExpandLargeFpConvert.h"
|
||||
#include "llvm/CodeGen/ExpandMemCmp.h"
|
||||
#include "llvm/CodeGen/GCMetadata.h"
|
||||
#include "llvm/CodeGen/HardwareLoops.h"
|
||||
#include "llvm/CodeGen/IndirectBrExpand.h"
|
||||
|
@ -308,6 +308,7 @@ FUNCTION_PASS("dse", DSEPass())
|
||||
FUNCTION_PASS("dwarf-eh-prepare", DwarfEHPreparePass(TM))
|
||||
FUNCTION_PASS("expand-large-div-rem", ExpandLargeDivRemPass(TM))
|
||||
FUNCTION_PASS("expand-large-fp-convert", ExpandLargeFpConvertPass(TM))
|
||||
FUNCTION_PASS("expand-memcmp", ExpandMemCmpPass(TM))
|
||||
FUNCTION_PASS("fix-irreducible", FixIrreduciblePass())
|
||||
FUNCTION_PASS("flattencfg", FlattenCFGPass())
|
||||
FUNCTION_PASS("float2int", Float2IntPass())
|
||||
|
@ -1,7 +1,7 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
||||
; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple=powerpc64le-unknown-gnu-linux < %s | FileCheck %s -check-prefix=PPC64LE
|
||||
|
||||
; This tests interaction between MergeICmp and ExpandMemCmp.
|
||||
; This tests interaction between MergeICmp and expand-memcmp.
|
||||
|
||||
%"struct.std::pair" = type { i32, i32 }
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
|
||||
; RUN: opt -S -expandmemcmp -memcmp-num-loads-per-block=1 -mtriple=aarch64-unknown-unknown < %s | FileCheck %s
|
||||
; RUN: opt -S -expand-memcmp -memcmp-num-loads-per-block=1 -mtriple=aarch64-unknown-unknown < %s | FileCheck %s
|
||||
; RUN: opt -S -passes=expand-memcmp -memcmp-num-loads-per-block=1 -mtriple=aarch64-unknown-unknown < %s | FileCheck %s
|
||||
|
||||
declare i32 @memcmp(ptr nocapture, ptr nocapture, i64)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt -S -expandmemcmp -memcmp-num-loads-per-block=1 -mtriple=x86_64-unknown-unknown -data-layout=e-m:o-i64:64-f80:128-n8:16:32:64-S128 < %s | FileCheck %s --check-prefix=X64
|
||||
; RUN: opt -S -expand-memcmp -memcmp-num-loads-per-block=1 -mtriple=x86_64-unknown-unknown -data-layout=e-m:o-i64:64-f80:128-n8:16:32:64-S128 < %s | FileCheck %s --check-prefix=X64
|
||||
; RUN: opt -S -passes=expand-memcmp -memcmp-num-loads-per-block=1 -mtriple=x86_64-unknown-unknown -data-layout=e-m:o-i64:64-f80:128-n8:16:32:64-S128 < %s | FileCheck %s --check-prefix=X64
|
||||
|
||||
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt -S -expandmemcmp -mtriple=i686-unknown-unknown -data-layout=e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128 < %s | FileCheck %s --check-prefix=X32
|
||||
; RUN: opt -S -expand-memcmp -mtriple=i686-unknown-unknown -data-layout=e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128 < %s | FileCheck %s --check-prefix=X32
|
||||
; RUN: opt -S -passes=expand-memcmp -mtriple=i686-unknown-unknown -data-layout=e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128 < %s | FileCheck %s --check-prefix=X32
|
||||
|
||||
declare i32 @memcmp(ptr nocapture, ptr nocapture, i32)
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt -S -expandmemcmp -memcmp-num-loads-per-block=1 -mtriple=x86_64-unknown-unknown -data-layout=e-m:o-i64:64-f80:128-n8:16:32:64-S128 < %s | FileCheck %s --check-prefix=X64 --check-prefix=X64_1LD
|
||||
; RUN: opt -S -expandmemcmp -memcmp-num-loads-per-block=2 -mtriple=x86_64-unknown-unknown -data-layout=e-m:o-i64:64-f80:128-n8:16:32:64-S128 < %s | FileCheck %s --check-prefix=X64 --check-prefix=X64_2LD
|
||||
; RUN: opt -S -expand-memcmp -memcmp-num-loads-per-block=1 -mtriple=x86_64-unknown-unknown -data-layout=e-m:o-i64:64-f80:128-n8:16:32:64-S128 < %s | FileCheck %s --check-prefix=X64 --check-prefix=X64_1LD
|
||||
; RUN: opt -S -expand-memcmp -memcmp-num-loads-per-block=2 -mtriple=x86_64-unknown-unknown -data-layout=e-m:o-i64:64-f80:128-n8:16:32:64-S128 < %s | FileCheck %s --check-prefix=X64 --check-prefix=X64_2LD
|
||||
; RUN: opt -S -passes=expand-memcmp -memcmp-num-loads-per-block=1 -mtriple=x86_64-unknown-unknown -data-layout=e-m:o-i64:64-f80:128-n8:16:32:64-S128 < %s | FileCheck %s --check-prefix=X64 --check-prefix=X64_1LD
|
||||
; RUN: opt -S -passes=expand-memcmp -memcmp-num-loads-per-block=2 -mtriple=x86_64-unknown-unknown -data-layout=e-m:o-i64:64-f80:128-n8:16:32:64-S128 < %s | FileCheck %s --check-prefix=X64 --check-prefix=X64_2LD
|
||||
|
||||
declare i32 @memcmp(ptr nocapture, ptr nocapture, i64)
|
||||
|
||||
|
@ -356,7 +356,7 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) {
|
||||
"expand-reductions",
|
||||
"indirectbr-expand",
|
||||
"generic-to-nvvm",
|
||||
"expandmemcmp",
|
||||
"expand-memcmp",
|
||||
"loop-reduce",
|
||||
"lower-amx-type",
|
||||
"lower-amx-intrinsics",
|
||||
@ -422,7 +422,7 @@ int main(int argc, char **argv) {
|
||||
// supported.
|
||||
initializeExpandLargeDivRemLegacyPassPass(Registry);
|
||||
initializeExpandLargeFpConvertLegacyPassPass(Registry);
|
||||
initializeExpandMemCmpPassPass(Registry);
|
||||
initializeExpandMemCmpLegacyPassPass(Registry);
|
||||
initializeScalarizeMaskedMemIntrinLegacyPassPass(Registry);
|
||||
initializeSelectOptimizePass(Registry);
|
||||
initializeCallBrPreparePass(Registry);
|
||||
|
Loading…
x
Reference in New Issue
Block a user