mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 06:46:33 +00:00
[CodeGen][NPM] Port BranchRelaxation to NPM (#130067)
This completes the PreEmitPasses.
This commit is contained in:
parent
2ff226ae2c
commit
b283ff7eb1
25
llvm/include/llvm/CodeGen/BranchRelaxation.h
Normal file
25
llvm/include/llvm/CodeGen/BranchRelaxation.h
Normal file
@ -0,0 +1,25 @@
|
||||
//===- llvm/CodeGen/BranchRelaxation.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_BRANCHRELAXATION_H
|
||||
#define LLVM_CODEGEN_BRANCHRELAXATION_H
|
||||
|
||||
#include "llvm/CodeGen/MachinePassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class BranchRelaxationPass : public PassInfoMixin<BranchRelaxationPass> {
|
||||
public:
|
||||
PreservedAnalyses run(MachineFunction &MF,
|
||||
MachineFunctionAnalysisManager &MFAM);
|
||||
static bool isRequired() { return true; }
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_CODEGEN_BRANCHRELAXATION_H
|
@ -61,7 +61,7 @@ void initializeBasicAAWrapperPassPass(PassRegistry &);
|
||||
void initializeBlockFrequencyInfoWrapperPassPass(PassRegistry &);
|
||||
void initializeBranchFolderLegacyPass(PassRegistry &);
|
||||
void initializeBranchProbabilityInfoWrapperPassPass(PassRegistry &);
|
||||
void initializeBranchRelaxationPass(PassRegistry &);
|
||||
void initializeBranchRelaxationLegacyPass(PassRegistry &);
|
||||
void initializeBreakCriticalEdgesPass(PassRegistry &);
|
||||
void initializeBreakFalseDepsPass(PassRegistry &);
|
||||
void initializeCanonicalizeFreezeInLoopsPass(PassRegistry &);
|
||||
|
@ -137,6 +137,7 @@ MACHINE_FUNCTION_ANALYSIS("virtregmap", VirtRegMapAnalysis())
|
||||
#ifndef MACHINE_FUNCTION_PASS
|
||||
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
|
||||
#endif
|
||||
MACHINE_FUNCTION_PASS("branch-relaxation", BranchRelaxationPass())
|
||||
MACHINE_FUNCTION_PASS("dead-mi-elimination", DeadMachineInstructionElimPass())
|
||||
MACHINE_FUNCTION_PASS("detect-dead-lanes", DetectDeadLanesPass())
|
||||
MACHINE_FUNCTION_PASS("early-ifcvt", EarlyIfConverterPass())
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/CodeGen/BranchRelaxation.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/CodeGen/LivePhysRegs.h"
|
||||
@ -44,7 +45,7 @@ STATISTIC(NumUnconditionalRelaxed, "Number of unconditional branches relaxed");
|
||||
|
||||
namespace {
|
||||
|
||||
class BranchRelaxation : public MachineFunctionPass {
|
||||
class BranchRelaxation {
|
||||
/// BasicBlockInfo - Information about the offset and size of a single
|
||||
/// basic block.
|
||||
struct BasicBlockInfo {
|
||||
@ -115,23 +116,31 @@ class BranchRelaxation : public MachineFunctionPass {
|
||||
void dumpBBs();
|
||||
void verify();
|
||||
|
||||
public:
|
||||
bool run(MachineFunction &MF);
|
||||
};
|
||||
|
||||
class BranchRelaxationLegacy : public MachineFunctionPass {
|
||||
public:
|
||||
static char ID;
|
||||
|
||||
BranchRelaxation() : MachineFunctionPass(ID) {}
|
||||
BranchRelaxationLegacy() : MachineFunctionPass(ID) {}
|
||||
|
||||
bool runOnMachineFunction(MachineFunction &MF) override;
|
||||
bool runOnMachineFunction(MachineFunction &MF) override {
|
||||
return BranchRelaxation().run(MF);
|
||||
}
|
||||
|
||||
StringRef getPassName() const override { return BRANCH_RELAX_NAME; }
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
char BranchRelaxation::ID = 0;
|
||||
char BranchRelaxationLegacy::ID = 0;
|
||||
|
||||
char &llvm::BranchRelaxationPassID = BranchRelaxation::ID;
|
||||
char &llvm::BranchRelaxationPassID = BranchRelaxationLegacy::ID;
|
||||
|
||||
INITIALIZE_PASS(BranchRelaxation, DEBUG_TYPE, BRANCH_RELAX_NAME, false, false)
|
||||
INITIALIZE_PASS(BranchRelaxationLegacy, DEBUG_TYPE, BRANCH_RELAX_NAME, false,
|
||||
false)
|
||||
|
||||
/// verify - check BBOffsets, BBSizes, alignment of islands
|
||||
void BranchRelaxation::verify() {
|
||||
@ -744,7 +753,16 @@ bool BranchRelaxation::relaxBranchInstructions() {
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool BranchRelaxation::runOnMachineFunction(MachineFunction &mf) {
|
||||
PreservedAnalyses
|
||||
BranchRelaxationPass::run(MachineFunction &MF,
|
||||
MachineFunctionAnalysisManager &MFAM) {
|
||||
if (!BranchRelaxation().run(MF))
|
||||
return PreservedAnalyses::all();
|
||||
|
||||
return getMachineFunctionPassPreservedAnalyses();
|
||||
}
|
||||
|
||||
bool BranchRelaxation::run(MachineFunction &mf) {
|
||||
MF = &mf;
|
||||
|
||||
LLVM_DEBUG(dbgs() << "***** BranchRelaxation *****\n");
|
||||
|
@ -23,7 +23,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
|
||||
initializeBasicBlockPathCloningPass(Registry);
|
||||
initializeBasicBlockSectionsPass(Registry);
|
||||
initializeBranchFolderLegacyPass(Registry);
|
||||
initializeBranchRelaxationPass(Registry);
|
||||
initializeBranchRelaxationLegacyPass(Registry);
|
||||
initializeBreakFalseDepsPass(Registry);
|
||||
initializeCallBrPreparePass(Registry);
|
||||
initializeCFGuardLongjmpPass(Registry);
|
||||
|
@ -82,6 +82,7 @@
|
||||
#include "llvm/CodeGen/AtomicExpand.h"
|
||||
#include "llvm/CodeGen/BasicBlockSectionsProfileReader.h"
|
||||
#include "llvm/CodeGen/BranchFoldingPass.h"
|
||||
#include "llvm/CodeGen/BranchRelaxation.h"
|
||||
#include "llvm/CodeGen/CallBrPrepare.h"
|
||||
#include "llvm/CodeGen/CodeGenPrepare.h"
|
||||
#include "llvm/CodeGen/ComplexDeinterleavingPass.h"
|
||||
|
@ -66,6 +66,7 @@
|
||||
#include "llvm/Analysis/KernelInfo.h"
|
||||
#include "llvm/Analysis/UniformityAnalysis.h"
|
||||
#include "llvm/CodeGen/AtomicExpand.h"
|
||||
#include "llvm/CodeGen/BranchRelaxation.h"
|
||||
#include "llvm/CodeGen/DeadMachineInstructionElim.h"
|
||||
#include "llvm/CodeGen/GlobalISel/CSEInfo.h"
|
||||
#include "llvm/CodeGen/GlobalISel/IRTranslator.h"
|
||||
@ -2205,7 +2206,7 @@ void AMDGPUCodeGenPassBuilder::addPreEmitPass(AddMachinePass &addPass) const {
|
||||
addPass(AMDGPUInsertDelayAluPass());
|
||||
}
|
||||
|
||||
// TODO: addPass(BranchRelaxationPass());
|
||||
addPass(BranchRelaxationPass());
|
||||
}
|
||||
|
||||
bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
|
||||
|
@ -1,5 +1,6 @@
|
||||
# REQUIRES: asserts
|
||||
# RUN: llc -mtriple=aarch64--linux-gnu -run-pass=branch-relaxation -debug-only=branch-relaxation %s -o /dev/null 2>&1 | FileCheck %s
|
||||
# RUN: llc -mtriple=aarch64--linux-gnu -passes=branch-relaxation -debug-only=branch-relaxation %s -o /dev/null 2>&1 | FileCheck %s
|
||||
|
||||
# Ensure meta instructions (e.g. CFI_INSTRUCTION) don't contribute to the code
|
||||
# size of a basic block.
|
||||
|
@ -1,6 +1,8 @@
|
||||
# RUN: llc -mtriple=aarch64-none-linux-gnu -run-pass branch-relaxation -aarch64-b-offset-bits=64 -aarch64-tbz-offset-bits=9 -aarch64-cbz-offset-bits=9 %s -o - | FileCheck %s
|
||||
# RUN: llc -mtriple=aarch64-none-linux-gnu -run-pass branch-relaxation -aarch64-tbz-offset-bits=9 -aarch64-cbz-offset-bits=9 %s -o - | FileCheck --check-prefix=INDIRECT %s
|
||||
|
||||
# RUN: llc -mtriple=aarch64-none-linux-gnu -passes branch-relaxation -aarch64-tbz-offset-bits=9 -aarch64-cbz-offset-bits=9 %s -o - | FileCheck --check-prefix=INDIRECT %s
|
||||
|
||||
--- |
|
||||
declare i32 @bar()
|
||||
declare i32 @baz()
|
||||
|
@ -1,5 +1,6 @@
|
||||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
|
||||
# RUN: llc -verify-machineinstrs -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a --amdgpu-s-branch-bits=5 -run-pass branch-relaxation %s -o - | FileCheck %s
|
||||
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a --amdgpu-s-branch-bits=5 -passes=branch-relaxation %s -o - | FileCheck %s
|
||||
|
||||
---
|
||||
name: branch_no_terminators
|
||||
|
Loading…
x
Reference in New Issue
Block a user