Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/CodeGen/Address.h
Line
Count
Source (jump to first uncovered line)
1
//===-- Address.h - An aligned address -------------------------*- 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 class provides a simple wrapper for a pair of a pointer and an
10
// alignment.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_LIB_CODEGEN_ADDRESS_H
15
#define LLVM_CLANG_LIB_CODEGEN_ADDRESS_H
16
17
#include "llvm/IR/Constants.h"
18
#include "clang/AST/CharUnits.h"
19
20
namespace clang {
21
namespace CodeGen {
22
23
/// An aligned address.
24
class Address {
25
  llvm::Value *Pointer;
26
  CharUnits Alignment;
27
public:
28
  Address(llvm::Value *pointer, CharUnits alignment)
29
29.9M
      : Pointer(pointer), Alignment(alignment) {
30
29.9M
    assert((!alignment.isZero() || pointer == nullptr) &&
31
29.9M
           "creating valid address with invalid alignment");
32
29.9M
  }
33
34
17.3M
  static Address invalid() { return Address(nullptr, CharUnits()); }
35
8.35M
  bool isValid() const { return Pointer != nullptr; }
36
37
24.2M
  llvm::Value *getPointer() const {
38
24.2M
    assert(isValid());
39
24.2M
    return Pointer;
40
24.2M
  }
41
42
  /// Return the type of the pointer value.
43
3.08M
  llvm::PointerType *getType() const {
44
3.08M
    return llvm::cast<llvm::PointerType>(getPointer()->getType());
45
3.08M
  }
46
47
  /// Return the type of the values stored in this address.
48
  ///
49
  /// When IR pointer types lose their element type, we should simply
50
  /// store it in Address instead for the convenience of writing code.
51
1.82M
  llvm::Type *getElementType() const {
52
1.82M
    return getType()->getElementType();
53
1.82M
  }
54
55
  /// Return the address space that this address resides in.
56
1.10M
  unsigned getAddressSpace() const {
57
1.10M
    return getType()->getAddressSpace();
58
1.10M
  }
59
60
  /// Return the IR name of the pointer value.
61
11.8k
  llvm::StringRef getName() const {
62
11.8k
    return getPointer()->getName();
63
11.8k
  }
64
65
  /// Return the alignment of this pointer.
66
16.8M
  CharUnits getAlignment() const {
67
16.8M
    assert(isValid());
68
16.8M
    return Alignment;
69
16.8M
  }
70
};
71
72
/// A specialization of Address that requires the address to be an
73
/// LLVM Constant.
74
class ConstantAddress : public Address {
75
public:
76
  ConstantAddress(llvm::Constant *pointer, CharUnits alignment)
77
172k
    : Address(pointer, alignment) {}
78
79
1.46k
  static ConstantAddress invalid() {
80
1.46k
    return ConstantAddress(nullptr, CharUnits());
81
1.46k
  }
82
83
23.9k
  llvm::Constant *getPointer() const {
84
23.9k
    return llvm::cast<llvm::Constant>(Address::getPointer());
85
23.9k
  }
86
87
32
  ConstantAddress getBitCast(llvm::Type *ty) const {
88
32
    return ConstantAddress(llvm::ConstantExpr::getBitCast(getPointer(), ty),
89
32
                           getAlignment());
90
32
  }
91
92
32
  ConstantAddress getElementBitCast(llvm::Type *ty) const {
93
32
    return getBitCast(ty->getPointerTo(getAddressSpace()));
94
32
  }
95
96
0
  static bool isaImpl(Address addr) {
97
0
    return llvm::isa<llvm::Constant>(addr.getPointer());
98
0
  }
99
0
  static ConstantAddress castImpl(Address addr) {
100
0
    return ConstantAddress(llvm::cast<llvm::Constant>(addr.getPointer()),
101
0
                           addr.getAlignment());
102
0
  }
103
};
104
105
}
106
107
// Present a minimal LLVM-like casting interface.
108
template <class U> inline U cast(CodeGen::Address addr) {
109
  return U::castImpl(addr);
110
}
111
template <class U> inline bool isa(CodeGen::Address addr) {
112
  return U::isaImpl(addr);
113
}
114
115
}
116
117
#endif