blob: 0777add2e73d72abfb50f0283d8f6ee6d4d4b4f4 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- llvm/MC/MCInstrAnalysis.h - InstrDesc target hooks -------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the MCInstrAnalysis class which the MCTargetDescs can
11// derive from to give additional information to MC.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_MC_MCINSTRANALYSIS_H
16#define LLVM_MC_MCINSTRANALYSIS_H
17
18#include "llvm/MC/MCInst.h"
19#include "llvm/MC/MCInstrDesc.h"
20#include "llvm/MC/MCInstrInfo.h"
21#include <cstdint>
22
23namespace llvm {
24
Andrew Scullcdfcccc2018-10-05 20:58:37 +010025class MCRegisterInfo;
26class Triple;
27
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010028class MCInstrAnalysis {
29protected:
30 friend class Target;
31
32 const MCInstrInfo *Info;
33
34public:
35 MCInstrAnalysis(const MCInstrInfo *Info) : Info(Info) {}
36 virtual ~MCInstrAnalysis() = default;
37
38 virtual bool isBranch(const MCInst &Inst) const {
39 return Info->get(Inst.getOpcode()).isBranch();
40 }
41
42 virtual bool isConditionalBranch(const MCInst &Inst) const {
43 return Info->get(Inst.getOpcode()).isConditionalBranch();
44 }
45
46 virtual bool isUnconditionalBranch(const MCInst &Inst) const {
47 return Info->get(Inst.getOpcode()).isUnconditionalBranch();
48 }
49
50 virtual bool isIndirectBranch(const MCInst &Inst) const {
51 return Info->get(Inst.getOpcode()).isIndirectBranch();
52 }
53
54 virtual bool isCall(const MCInst &Inst) const {
55 return Info->get(Inst.getOpcode()).isCall();
56 }
57
58 virtual bool isReturn(const MCInst &Inst) const {
59 return Info->get(Inst.getOpcode()).isReturn();
60 }
61
62 virtual bool isTerminator(const MCInst &Inst) const {
63 return Info->get(Inst.getOpcode()).isTerminator();
64 }
65
Andrew Scullcdfcccc2018-10-05 20:58:37 +010066 /// Returns true if at least one of the register writes performed by
67 /// \param Inst implicitly clears the upper portion of all super-registers.
68 ///
69 /// Example: on X86-64, a write to EAX implicitly clears the upper half of
70 /// RAX. Also (still on x86) an XMM write perfomed by an AVX 128-bit
71 /// instruction implicitly clears the upper portion of the correspondent
72 /// YMM register.
73 ///
74 /// This method also updates an APInt which is used as mask of register
75 /// writes. There is one bit for every explicit/implicit write performed by
76 /// the instruction. If a write implicitly clears its super-registers, then
77 /// the corresponding bit is set (vic. the corresponding bit is cleared).
78 ///
79 /// The first bits in the APint are related to explicit writes. The remaining
80 /// bits are related to implicit writes. The sequence of writes follows the
81 /// machine operand sequence. For implicit writes, the sequence is defined by
82 /// the MCInstrDesc.
83 ///
84 /// The assumption is that the bit-width of the APInt is correctly set by
85 /// the caller. The default implementation conservatively assumes that none of
86 /// the writes clears the upper portion of a super-register.
87 virtual bool clearsSuperRegisters(const MCRegisterInfo &MRI,
88 const MCInst &Inst,
89 APInt &Writes) const;
90
91 /// Returns true if \param Inst is a dependency breaking instruction for the
92 /// given subtarget.
93 ///
94 /// The value computed by a dependency breaking instruction is not dependent
95 /// on the inputs. An example of dependency breaking instruction on X86 is
96 /// `XOR %eax, %eax`.
97 /// TODO: In future, we could implement an alternative approach where this
98 /// method returns `true` if the input instruction is not dependent on
99 /// some/all of its input operands. An APInt mask could then be used to
100 /// identify independent operands.
101 virtual bool isDependencyBreaking(const MCSubtargetInfo &STI,
102 const MCInst &Inst) const;
103
104 /// Given a branch instruction try to get the address the branch
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100105 /// targets. Return true on success, and the address in Target.
106 virtual bool
107 evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
108 uint64_t &Target) const;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100109
110 /// Returns (PLT virtual address, GOT virtual address) pairs for PLT entries.
111 virtual std::vector<std::pair<uint64_t, uint64_t>>
112 findPltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
113 uint64_t GotPltSectionVA, const Triple &TargetTriple) const {
114 return {};
115 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100116};
117
118} // end namespace llvm
119
120#endif // LLVM_MC_MCINSTRANALYSIS_H