================ @@ -0,0 +1,561 @@ +//===---- LoongArchMemoryBarrierOpt.cpp - Memory barrier Optimization -----===// +// +// 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 +// +//===----------------------------------------------------------------------===// +/// +/// This pass removes or merges redundant memory barrier instructions. +/// +/// - DBAR x + DBAR y -> DBAR (x & y) +/// - DBAR x + AMO_DB -> AMO_DB +/// - DBAR x + AMO -> AMO_DB +/// - DBAR x + LL -> LL +/// - AMO_DB + DBAR x -> AMO_DB +/// - AMO + DBAR x -> AMO_DB +/// - SC + DBAR x -> SC +/// +//===----------------------------------------------------------------------===// + +#include "LoongArch.h" +#include "LoongArchInstrInfo.h" +#include "LoongArchSubtarget.h" +#include "llvm/CodeGen/MachineDominators.h" +#include "llvm/CodeGen/MachinePostDominators.h" +#include "llvm/InitializePasses.h" + +using namespace llvm; + +#define DEBUG_TYPE "loongarch-memory-barrier-opt" +#define LOONGARCH_MEMORY_BARRIER_OPT_NAME \ + "LoongArch Memory Barrier Optimisation pass" + +static cl::opt<bool> RequireNoPathBypass( + "loongarch-require-no-path-bypass", + cl::desc("Optimize only when no paths bypass either memory barrier"), + cl::init(true), cl::Hidden); + +static cl::opt<bool> MergeAMOWithMB( + "loongarch-merge-amo-with-dbar", + cl::desc("Merge AMOs with DBARs into AMO_DB during optimization"), + cl::init(true), cl::Hidden); + +static cl::opt<bool> DisableInlineAsm( + "loongarch-disable-inline-asm-barrier-opt", + cl::desc("Disable optimization of memory barriers in InlineAsm"), + cl::init(false), cl::Hidden); ---------------- nikic wrote:
This is violating inline assembly semantics: https://llvm.org/docs/LangRef.html#inline-assembler-expressions > The compiler may not assume that the actual code executed at runtime matches > the contents of the template string. Correctness-critical analyses must base > their results only on the list of operand constraints and the flags – not the > contents of the template string. This ensures correct behavior if the > assembly code emitted by this expression is altered later, e.g. via > self-modifying code, as long as the code keeps upholding the requirements of > the operand constraints and the flags. Please revert this commit. (Changing the default is not sufficient.) https://github.com/llvm/llvm-project/pull/218597 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
