xref: /llvm-project/llvm/lib/Target/X86/MCA/X86CustomBehaviour.cpp (revision ed8019d9fbed2e6a6b08f8f73e9fa54a24f3ed52)
185e6e748SPatrick Holland //===------------------- X86CustomBehaviour.cpp -----------------*-C++ -* -===//
285e6e748SPatrick Holland //
385e6e748SPatrick Holland // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
485e6e748SPatrick Holland // See https://llvm.org/LICENSE.txt for license information.
585e6e748SPatrick Holland // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
685e6e748SPatrick Holland //
785e6e748SPatrick Holland //===----------------------------------------------------------------------===//
885e6e748SPatrick Holland /// \file
985e6e748SPatrick Holland ///
1085e6e748SPatrick Holland /// This file implements methods from the X86CustomBehaviour class.
1185e6e748SPatrick Holland ///
1285e6e748SPatrick Holland //===----------------------------------------------------------------------===//
1385e6e748SPatrick Holland 
1485e6e748SPatrick Holland #include "X86CustomBehaviour.h"
155bc514b7SReid Kleckner #include "MCTargetDesc/X86BaseInfo.h"
16*ed8019d9SKazu Hirata #include "TargetInfo/X86TargetInfo.h"
1785e6e748SPatrick Holland #include "llvm/MC/TargetRegistry.h"
1885e6e748SPatrick Holland 
1985e6e748SPatrick Holland namespace llvm {
2085e6e748SPatrick Holland namespace mca {
2185e6e748SPatrick Holland 
2285e6e748SPatrick Holland void X86InstrPostProcess::setMemBarriers(std::unique_ptr<Instruction> &Inst,
2385e6e748SPatrick Holland                                          const MCInst &MCI) {
2485e6e748SPatrick Holland   switch (MCI.getOpcode()) {
2585e6e748SPatrick Holland   case X86::MFENCE:
2685e6e748SPatrick Holland     Inst->setLoadBarrier(true);
2785e6e748SPatrick Holland     Inst->setStoreBarrier(true);
2885e6e748SPatrick Holland     break;
2985e6e748SPatrick Holland   case X86::LFENCE:
3085e6e748SPatrick Holland     Inst->setLoadBarrier(true);
3185e6e748SPatrick Holland     break;
3285e6e748SPatrick Holland   case X86::SFENCE:
3385e6e748SPatrick Holland     Inst->setStoreBarrier(true);
3485e6e748SPatrick Holland     break;
3585e6e748SPatrick Holland   }
3685e6e748SPatrick Holland }
3785e6e748SPatrick Holland 
3885e6e748SPatrick Holland void X86InstrPostProcess::postProcessInstruction(
3985e6e748SPatrick Holland     std::unique_ptr<Instruction> &Inst, const MCInst &MCI) {
4085e6e748SPatrick Holland   // Currently, we only modify certain instructions' IsALoadBarrier and
4185e6e748SPatrick Holland   // IsAStoreBarrier flags.
4285e6e748SPatrick Holland   setMemBarriers(Inst, MCI);
4385e6e748SPatrick Holland }
4485e6e748SPatrick Holland 
4585e6e748SPatrick Holland } // namespace mca
4685e6e748SPatrick Holland } // namespace llvm
4785e6e748SPatrick Holland 
4885e6e748SPatrick Holland using namespace llvm;
4985e6e748SPatrick Holland using namespace mca;
5085e6e748SPatrick Holland 
5185e6e748SPatrick Holland static InstrPostProcess *createX86InstrPostProcess(const MCSubtargetInfo &STI,
5285e6e748SPatrick Holland                                                    const MCInstrInfo &MCII) {
5385e6e748SPatrick Holland   return new X86InstrPostProcess(STI, MCII);
5485e6e748SPatrick Holland }
5585e6e748SPatrick Holland 
5685e6e748SPatrick Holland /// Extern function to initialize the targets for the X86 backend
5785e6e748SPatrick Holland 
587760ae7bSThomas Fransham extern "C" LLVM_C_ABI void LLVMInitializeX86TargetMCA() {
5985e6e748SPatrick Holland   TargetRegistry::RegisterInstrPostProcess(getTheX86_32Target(),
6085e6e748SPatrick Holland                                            createX86InstrPostProcess);
6185e6e748SPatrick Holland   TargetRegistry::RegisterInstrPostProcess(getTheX86_64Target(),
6285e6e748SPatrick Holland                                            createX86InstrPostProcess);
6385e6e748SPatrick Holland }
64