Skip to content

Commit

Permalink
CodeGen: Port ExpandLargeDivRem to new pass manager (#71022)
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenm committed Nov 2, 2023
1 parent 2b67942 commit 94202e7
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 1 deletion.
30 changes: 30 additions & 0 deletions llvm/include/llvm/CodeGen/ExpandLargeDivRem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===- ExpandLargeDivRem.h --------------------------------------*- 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_EXPANDLARGEDIVREM_H
#define LLVM_CODEGEN_EXPANDLARGEDIVREM_H

#include "llvm/IR/PassManager.h"

namespace llvm {

class TargetMachine;

class ExpandLargeDivRemPass : public PassInfoMixin<ExpandLargeDivRemPass> {
private:
const TargetMachine *TM;

public:
explicit ExpandLargeDivRemPass(const TargetMachine *TM_) : TM(TM_) {}

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};

} // end namespace llvm

#endif // LLVM_CODEGEN_EXPANDLARGEDIVREM_H
8 changes: 8 additions & 0 deletions llvm/lib/CodeGen/ExpandLargeDivRem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//
//===----------------------------------------------------------------------===//

#include "llvm/CodeGen/ExpandLargeDivRem.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/GlobalsModRef.h"
Expand Down Expand Up @@ -128,6 +129,13 @@ class ExpandLargeDivRemLegacyPass : public FunctionPass {
};
} // namespace

PreservedAnalyses ExpandLargeDivRemPass::run(Function &F,
FunctionAnalysisManager &FAM) {
const TargetSubtargetInfo *STI = TM->getSubtargetImpl(F);
return runImpl(F, *STI->getTargetLowering()) ? PreservedAnalyses::none()
: PreservedAnalyses::all();
}

char ExpandLargeDivRemLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(ExpandLargeDivRemLegacyPass, "expand-large-div-rem",
"Expand large div/rem", false, false)
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
#include "llvm/Analysis/UniformityAnalysis.h"
#include "llvm/CodeGen/ExpandLargeDivRem.h"
#include "llvm/CodeGen/HardwareLoops.h"
#include "llvm/CodeGen/TypePromotion.h"
#include "llvm/IR/DebugInfo.h"
Expand Down Expand Up @@ -234,8 +235,8 @@
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
#include "llvm/Transforms/Utils/CanonicalizeFreezeInLoops.h"
#include "llvm/Transforms/Utils/CountVisits.h"
#include "llvm/Transforms/Utils/Debugify.h"
#include "llvm/Transforms/Utils/DXILUpgrade.h"
#include "llvm/Transforms/Utils/Debugify.h"
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
#include "llvm/Transforms/Utils/FixIrreducible.h"
#include "llvm/Transforms/Utils/HelloWorld.h"
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
FUNCTION_PASS("tsan", ThreadSanitizerPass())
FUNCTION_PASS("memprof", MemProfilerPass())
FUNCTION_PASS("declare-to-assign", llvm::AssignmentTrackingPass())
FUNCTION_PASS("expand-large-div-rem", ExpandLargeDivRemPass(TM));
#undef FUNCTION_PASS

#ifndef FUNCTION_PASS_WITH_PARAMS
Expand Down
1 change: 1 addition & 0 deletions llvm/test/Transforms/ExpandLargeDivRem/X86/sdiv129.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -mtriple=x86_64-- -expand-large-div-rem -expand-div-rem-bits 128 < %s | FileCheck %s
; RUN: opt -S -mtriple=x86_64-- -passes=expand-large-div-rem -expand-div-rem-bits 128 < %s | FileCheck %s

define void @sdiv129(ptr %ptr, ptr %out) nounwind {
; CHECK-LABEL: @sdiv129(
Expand Down
1 change: 1 addition & 0 deletions llvm/test/Transforms/ExpandLargeDivRem/X86/srem129.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -mtriple=x86_64-- -expand-large-div-rem -expand-div-rem-bits 128 < %s | FileCheck %s
; RUN: opt -S -mtriple=x86_64-- -passes=expand-large-div-rem -expand-div-rem-bits 128 < %s | FileCheck %s

define void @test(ptr %ptr, ptr %out) nounwind {
; CHECK-LABEL: @test(
Expand Down
1 change: 1 addition & 0 deletions llvm/test/Transforms/ExpandLargeDivRem/X86/udiv129.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -mtriple=x86_64-- -expand-large-div-rem -expand-div-rem-bits 128 < %s | FileCheck %s
; RUN: opt -S -mtriple=x86_64-- -passes=expand-large-div-rem -expand-div-rem-bits 128 < %s | FileCheck %s

define void @test(ptr %ptr, ptr %out) nounwind {
; CHECK-LABEL: @test(
Expand Down
1 change: 1 addition & 0 deletions llvm/test/Transforms/ExpandLargeDivRem/X86/urem129.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -mtriple=x86_64-- -expand-large-div-rem -expand-div-rem-bits 128 < %s | FileCheck %s
; RUN: opt -S -mtriple=x86_64-- -passes=expand-large-div-rem -expand-div-rem-bits 128 < %s | FileCheck %s

define void @test(ptr %ptr, ptr %out) nounwind {
; CHECK-LABEL: @test(
Expand Down

0 comments on commit 94202e7

Please sign in to comment.