Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h
Line
Count
Source (jump to first uncovered line)
1
//===-- RISCVMCExpr.h - RISCV specific MC expression classes ----*- 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
//
9
// This file describes RISCV-specific MCExprs, used for modifiers like
10
// "%hi" or "%lo" etc.,
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCEXPR_H
15
#define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCEXPR_H
16
17
#include "llvm/MC/MCExpr.h"
18
19
namespace llvm {
20
21
class StringRef;
22
class MCOperand;
23
class RISCVMCExpr : public MCTargetExpr {
24
public:
25
  enum VariantKind {
26
    VK_RISCV_None,
27
    VK_RISCV_LO,
28
    VK_RISCV_HI,
29
    VK_RISCV_PCREL_LO,
30
    VK_RISCV_PCREL_HI,
31
    VK_RISCV_GOT_HI,
32
    VK_RISCV_TPREL_LO,
33
    VK_RISCV_TPREL_HI,
34
    VK_RISCV_TPREL_ADD,
35
    VK_RISCV_TLS_GOT_HI,
36
    VK_RISCV_TLS_GD_HI,
37
    VK_RISCV_CALL,
38
    VK_RISCV_CALL_PLT,
39
    VK_RISCV_Invalid
40
  };
41
42
private:
43
  const MCExpr *Expr;
44
  const VariantKind Kind;
45
46
  int64_t evaluateAsInt64(int64_t Value) const;
47
48
  bool evaluatePCRelLo(MCValue &Res, const MCAsmLayout *Layout,
49
                       const MCFixup *Fixup) const;
50
51
  explicit RISCVMCExpr(const MCExpr *Expr, VariantKind Kind)
52
2.93k
      : Expr(Expr), Kind(Kind) {}
53
54
public:
55
  static const RISCVMCExpr *create(const MCExpr *Expr, VariantKind Kind,
56
                                   MCContext &Ctx);
57
58
6.09k
  VariantKind getKind() const { return Kind; }
59
60
2.10k
  const MCExpr *getSubExpr() const { return Expr; }
61
62
  /// Get the corresponding PC-relative HI fixup that a VK_RISCV_PCREL_LO
63
  /// points to.
64
  ///
65
  /// \returns nullptr if this isn't a VK_RISCV_PCREL_LO pointing to a
66
  /// known PC-relative HI fixup.
67
  const MCFixup *getPCRelHiFixup() const;
68
69
  void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
70
  bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
71
                                 const MCFixup *Fixup) const override;
72
  void visitUsedExpr(MCStreamer &Streamer) const override;
73
168
  MCFragment *findAssociatedFragment() const override {
74
168
    return getSubExpr()->findAssociatedFragment();
75
168
  }
76
77
  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
78
79
  bool evaluateAsConstant(int64_t &Res) const;
80
81
6.72k
  static bool classof(const MCExpr *E) {
82
6.72k
    return E->getKind() == MCExpr::Target;
83
6.72k
  }
84
85
0
  static bool classof(const RISCVMCExpr *) { return true; }
86
87
  static VariantKind getVariantKindForName(StringRef name);
88
  static StringRef getVariantKindName(VariantKind Kind);
89
};
90
91
} // end namespace llvm.
92
93
#endif