Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
X86CustomBehaviour.cpp
Go to the documentation of this file.
1//===------------------- X86CustomBehaviour.cpp -----------------*-C++ -* -===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file implements methods from the X86CustomBehaviour class.
11///
12//===----------------------------------------------------------------------===//
13
14#include "X86CustomBehaviour.h"
17#include "llvm-c/Visibility.h"
19
20namespace llvm {
21namespace mca {
22
23void X86InstrPostProcess::setMemBarriers(Instruction &Inst, const MCInst &MCI) {
24 switch (MCI.getOpcode()) {
25 case X86::MFENCE:
26 Inst.setLoadBarrier(true);
27 Inst.setStoreBarrier(true);
28 break;
29 case X86::LFENCE:
30 Inst.setLoadBarrier(true);
31 break;
32 case X86::SFENCE:
33 Inst.setStoreBarrier(true);
34 break;
35 }
36}
37
38void X86InstrPostProcess::useStackEngine(Instruction &Inst, const MCInst &MCI) {
39 // TODO(boomanaiden154): We currently do not handle PUSHF/POPF because we
40 // have not done the necessary benchmarking to see if they are also
41 // optimized by the stack engine.
42 // TODO: We currently just remove all RSP writes from stack operations. This
43 // is not fully correct because we do not model sync uops which will
44 // delay subsequent rsp using non-stack instructions.
45 if (X86::isPOP(MCI.getOpcode()) || X86::isPUSH(MCI.getOpcode())) {
46 auto *StackRegisterDef =
47 llvm::find_if(Inst.getDefs(), [](const WriteState &State) {
48 return State.getRegisterID() == X86::RSP;
49 });
50 assert(
51 StackRegisterDef != Inst.getDefs().end() &&
52 "Expected push instruction to implicitly use stack pointer register.");
53 Inst.getDefs().erase(StackRegisterDef);
54 }
55}
56
58 const MCInst &MCI) {
59 // Set IsALoadBarrier and IsAStoreBarrier flags.
60 setMemBarriers(Inst, MCI);
61 useStackEngine(Inst, MCI);
62}
63
64} // namespace mca
65} // namespace llvm
66
67using namespace llvm;
68using namespace mca;
69
71 const MCInstrInfo &MCII) {
72 return new X86InstrPostProcess(STI, MCII);
73}
74
75/// Extern function to initialize the targets for the X86 backend
76
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_C_ABI
LLVM_C_ABI is the export/visibility macro used to mark symbols declared in llvm-c as exported when bu...
Definition Visibility.h:40
LLVM_C_ABI void LLVMInitializeX86TargetMCA()
Extern function to initialize the targets for the X86 backend.
static InstrPostProcess * createX86InstrPostProcess(const MCSubtargetInfo &STI, const MCInstrInfo &MCII)
This file defines the X86CustomBehaviour class which inherits from CustomBehaviour.
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
unsigned getOpcode() const
Definition MCInst.h:202
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
Generic base class for all target subtargets.
Class which can be overriden by targets to modify the mca::Instruction objects before the pipeline st...
An instruction propagated through the simulated instruction pipeline.
void postProcessInstruction(Instruction &Inst, const MCInst &MCI) override
This method can be overriden by targets to modify the mca::Instruction object after it has been lower...
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheX86_32Target()
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1738
Target & getTheX86_64Target()
static void RegisterInstrPostProcess(Target &T, Target::InstrPostProcessCtorTy Fn)
RegisterInstrPostProcess - Register an InstrPostProcess implementation for the given target.