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(std::unique_ptr<Instruction> &Inst,
24 const MCInst &MCI) {
25 switch (MCI.getOpcode()) {
26 case X86::MFENCE:
27 Inst->setLoadBarrier(true);
28 Inst->setStoreBarrier(true);
29 break;
30 case X86::LFENCE:
31 Inst->setLoadBarrier(true);
32 break;
33 case X86::SFENCE:
34 Inst->setStoreBarrier(true);
35 break;
36 }
37}
38
39void X86InstrPostProcess::useStackEngine(std::unique_ptr<Instruction> &Inst,
40 const MCInst &MCI) {
41 // TODO(boomanaiden154): We currently do not handle PUSHF/POPF because we
42 // have not done the necessary benchmarking to see if they are also
43 // optimized by the stack engine.
44 // TODO: We currently just remove all RSP writes from stack operations. This
45 // is not fully correct because we do not model sync uops which will
46 // delay subsequent rsp using non-stack instructions.
47 if (X86::isPOP(MCI.getOpcode()) || X86::isPUSH(MCI.getOpcode())) {
48 auto *StackRegisterDef =
49 llvm::find_if(Inst->getDefs(), [](const WriteState &State) {
50 return State.getRegisterID() == X86::RSP;
51 });
52 assert(
53 StackRegisterDef != Inst->getDefs().end() &&
54 "Expected push instruction to implicitly use stack pointer register.");
55 Inst->getDefs().erase(StackRegisterDef);
56 }
57}
58
60 std::unique_ptr<Instruction> &Inst, const MCInst &MCI) {
61 // Set IsALoadBarrier and IsAStoreBarrier flags.
62 setMemBarriers(Inst, MCI);
63 useStackEngine(Inst, MCI);
64}
65
66} // namespace mca
67} // namespace llvm
68
69using namespace llvm;
70using namespace mca;
71
73 const MCInstrInfo &MCII) {
74 return new X86InstrPostProcess(STI, MCII);
75}
76
77/// Extern function to initialize the targets for the X86 backend
78
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...
void postProcessInstruction(std::unique_ptr< 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.