
FixIrreducibleControlFlow pass adds dispatch blocks with a `br_table`
that has multiple predecessors and successors, because it serves as
something like a traffic hub for BBs. As a result of this, there can be
register uses that are not dominated by a def in every path from the
entry block. For example, suppose register %a is defined in BB1 and used
in BB2, and there is a single path from BB1 and BB2:
```
BB1 -> ... -> BB2
```
After FixIrreducibleControlFlow runs, there can be a dispatch block
between these two BBs:
```
BB1 -> ... -> Dispatch -> ... -> BB2
```
And this dispatch block has multiple predecessors, now
there is a path to BB2 that does not first visit BB1, and in that path
%a is not dominated by a def anymore.
To fix this problem, we have been adding `IMPLICIT_DEF`s to all
registers in PrepareForLiveInternals pass, and then remove unnecessary
ones in OptimizeLiveIntervals pass after computing `LiveIntervals`. But
FixIrreducibleControlFlow pass itself ends up violating register use-def
relationship, resulting in invalid code. This was OK so far because
MIR verifier apparently didn't check this in validation. But @arsenm
fixed this and it caught this bug in validation
(https://github.com/llvm/llvm-project/issues/55249).
This CL moves the `IMPLICIT_DEF` adding routine from
PrepareForLiveInternals to FixIrreducibleControlFlow. We only run it
when FixIrreducibleControlFlow changes the code. And then
PrepareForLiveInternals doesn't do anything other than setting
`TracksLiveness` property, which is a prerequisite for running
`LiveIntervals` analysis, which is required by the next pass
OptimizeLiveIntervals.
But in our backend we don't seem to do anything that invalidates this up
until OptimizeLiveIntervals, and I'm not sure why we are calling
`invalidateLiveness` in ReplacePhysRegs pass, because what that pass
does is to replace physical registers with virtual ones 1-to-1. I
deleted the `invalidateLiveness` call there and we don't need to set
that flag explicitly, which obviates all the need for
PrepareForLiveInternals.
(By the way, This 'Liveness' here is different from `LiveIntervals`
analysis. Setting this only means BBs' live-in info is correct, all uses
are dominated by defs, `kill` flag is conservatively correct, which
means if there is a `kill` flag set it should be the last use. See
2a0837aab1/llvm/include/llvm/CodeGen/MachineFunction.h (L125-L134)
for details.)
So this CL removes PrepareForLiveInternals pass altogether. Something
similar to this was attempted by D56091 long ago but that came short of
actually removing the pass, and I couldn't land it because
FixIrreducibleControlFlow violated use-def relationship, which this CL
fixes.
This doesn't change output in any meaningful way. All test changes
except `irreducible-cfg.mir` are register numbering.
Also this will likely to reduce compilation time, because we have been
adding `IMPLICIT_DEF` for all registers every time `-O2` is given, but
now we do that only when there is irreducible control flow, which is
rare.
Fixes https://github.com/llvm/llvm-project/issues/55249.
Reviewed By: dschuff, kripken
Differential Revision: https://reviews.llvm.org/D125515
106 lines
4.3 KiB
C++
106 lines
4.3 KiB
C++
//===-- WebAssembly.h - Top-level interface for WebAssembly ----*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// This file contains the entry points for global functions defined in
|
|
/// the LLVM WebAssembly back-end.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLY_H
|
|
#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLY_H
|
|
|
|
#include "llvm/PassRegistry.h"
|
|
#include "llvm/Support/CodeGen.h"
|
|
|
|
namespace llvm {
|
|
|
|
class WebAssemblyTargetMachine;
|
|
class ModulePass;
|
|
class FunctionPass;
|
|
|
|
// LLVM IR passes.
|
|
ModulePass *createWebAssemblyLowerEmscriptenEHSjLj();
|
|
ModulePass *createWebAssemblyAddMissingPrototypes();
|
|
ModulePass *createWebAssemblyFixFunctionBitcasts();
|
|
FunctionPass *createWebAssemblyOptimizeReturned();
|
|
FunctionPass *createWebAssemblyLowerRefTypesIntPtrConv();
|
|
|
|
// ISel and immediate followup passes.
|
|
FunctionPass *createWebAssemblyISelDag(WebAssemblyTargetMachine &TM,
|
|
CodeGenOpt::Level OptLevel);
|
|
FunctionPass *createWebAssemblyArgumentMove();
|
|
FunctionPass *createWebAssemblySetP2AlignOperands();
|
|
|
|
// Late passes.
|
|
FunctionPass *createWebAssemblyReplacePhysRegs();
|
|
FunctionPass *createWebAssemblyNullifyDebugValueLists();
|
|
FunctionPass *createWebAssemblyOptimizeLiveIntervals();
|
|
FunctionPass *createWebAssemblyMemIntrinsicResults();
|
|
FunctionPass *createWebAssemblyRegStackify();
|
|
FunctionPass *createWebAssemblyRegColoring();
|
|
FunctionPass *createWebAssemblyFixBrTableDefaults();
|
|
FunctionPass *createWebAssemblyFixIrreducibleControlFlow();
|
|
FunctionPass *createWebAssemblyLateEHPrepare();
|
|
FunctionPass *createWebAssemblyCFGSort();
|
|
FunctionPass *createWebAssemblyCFGStackify();
|
|
FunctionPass *createWebAssemblyExplicitLocals();
|
|
FunctionPass *createWebAssemblyLowerBrUnless();
|
|
FunctionPass *createWebAssemblyRegNumbering();
|
|
FunctionPass *createWebAssemblyDebugFixup();
|
|
FunctionPass *createWebAssemblyPeephole();
|
|
ModulePass *createWebAssemblyMCLowerPrePass();
|
|
|
|
// PassRegistry initialization declarations.
|
|
void initializeWebAssemblyAddMissingPrototypesPass(PassRegistry &);
|
|
void initializeWebAssemblyLowerEmscriptenEHSjLjPass(PassRegistry &);
|
|
void initializeFixFunctionBitcastsPass(PassRegistry &);
|
|
void initializeOptimizeReturnedPass(PassRegistry &);
|
|
void initializeWebAssemblyArgumentMovePass(PassRegistry &);
|
|
void initializeWebAssemblySetP2AlignOperandsPass(PassRegistry &);
|
|
void initializeWebAssemblyReplacePhysRegsPass(PassRegistry &);
|
|
void initializeWebAssemblyNullifyDebugValueListsPass(PassRegistry &);
|
|
void initializeWebAssemblyOptimizeLiveIntervalsPass(PassRegistry &);
|
|
void initializeWebAssemblyMemIntrinsicResultsPass(PassRegistry &);
|
|
void initializeWebAssemblyRegStackifyPass(PassRegistry &);
|
|
void initializeWebAssemblyRegColoringPass(PassRegistry &);
|
|
void initializeWebAssemblyFixBrTableDefaultsPass(PassRegistry &);
|
|
void initializeWebAssemblyFixIrreducibleControlFlowPass(PassRegistry &);
|
|
void initializeWebAssemblyLateEHPreparePass(PassRegistry &);
|
|
void initializeWebAssemblyExceptionInfoPass(PassRegistry &);
|
|
void initializeWebAssemblyCFGSortPass(PassRegistry &);
|
|
void initializeWebAssemblyCFGStackifyPass(PassRegistry &);
|
|
void initializeWebAssemblyExplicitLocalsPass(PassRegistry &);
|
|
void initializeWebAssemblyLowerBrUnlessPass(PassRegistry &);
|
|
void initializeWebAssemblyRegNumberingPass(PassRegistry &);
|
|
void initializeWebAssemblyDebugFixupPass(PassRegistry &);
|
|
void initializeWebAssemblyPeepholePass(PassRegistry &);
|
|
void initializeWebAssemblyMCLowerPrePassPass(PassRegistry &);
|
|
void initializeWebAssemblyLowerRefTypesIntPtrConvPass(PassRegistry &);
|
|
|
|
namespace WebAssembly {
|
|
enum TargetIndex {
|
|
// Followed by a local index (ULEB).
|
|
TI_LOCAL,
|
|
// Followed by an absolute global index (ULEB). DEPRECATED.
|
|
TI_GLOBAL_FIXED,
|
|
// Followed by the index from the bottom of the Wasm stack.
|
|
TI_OPERAND_STACK,
|
|
// Followed by a compilation unit relative global index (uint32_t)
|
|
// that will have an associated relocation.
|
|
TI_GLOBAL_RELOC,
|
|
// Like TI_LOCAL, but indicates an indirect value (e.g. byval arg
|
|
// passed by pointer).
|
|
TI_LOCAL_INDIRECT
|
|
};
|
|
} // end namespace WebAssembly
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif
|