aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/AsmParser/AsmParserContext.cpp
blob: fdc9940bb44b3ce57d51f9a675d6ab531684f99c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/AsmParser/AsmParserContext.h"

namespace llvm {

std::optional<FileLocRange>
AsmParserContext::getFunctionLocation(const Function *F) const {
  if (auto FIt = Functions.find(F); FIt != Functions.end())
    return FIt->second;
  return std::nullopt;
}

std::optional<FileLocRange>
AsmParserContext::getBlockLocation(const BasicBlock *BB) const {
  if (auto BBIt = Blocks.find(BB); BBIt != Blocks.end())
    return BBIt->second;
  return std::nullopt;
}

std::optional<FileLocRange>
AsmParserContext::getInstructionOrArgumentLocation(const Value *IA) const {
  assert(isa<Instruction>(IA) || isa<Argument>(IA));
  if (auto IIt = InstructionsAndArguments.find(IA);
      IIt != InstructionsAndArguments.end())
    return IIt->second;
  return std::nullopt;
}

Function *
AsmParserContext::getFunctionAtLocation(const FileLocRange &Query) const {
  auto It = FunctionsInverse.find(Query.Start);
  if (It.stop() <= Query.End)
    return *It;
  return nullptr;
}

Function *AsmParserContext::getFunctionAtLocation(const FileLoc &Query) const {
  return FunctionsInverse.lookup(Query, nullptr);
}

BasicBlock *
AsmParserContext::getBlockAtLocation(const FileLocRange &Query) const {
  auto It = BlocksInverse.find(Query.Start);
  if (It.stop() <= Query.End)
    return *It;
  return nullptr;
}

BasicBlock *AsmParserContext::getBlockAtLocation(const FileLoc &Query) const {
  return BlocksInverse.lookup(Query, nullptr);
}

Value *AsmParserContext::getInstructionOrArgumentAtLocation(
    const FileLocRange &Query) const {
  auto It = InstructionsAndArgumentsInverse.find(Query.Start);
  if (It.stop() <= Query.End)
    return *It;
  return nullptr;
}

Value *AsmParserContext::getInstructionOrArgumentAtLocation(
    const FileLoc &Query) const {
  return InstructionsAndArgumentsInverse.lookup(Query, nullptr);
}

Value *AsmParserContext::getValueReferencedAtLocation(
    const FileLocRange &Query) const {
  auto It = ReferencedValues.find(Query.Start);
  if (It.stop() <= Query.End)
    return *It;
  return nullptr;
}

Value *
AsmParserContext::getValueReferencedAtLocation(const FileLoc &Query) const {
  return ReferencedValues.lookup(Query, nullptr);
}

bool AsmParserContext::addFunctionLocation(Function *F,
                                           const FileLocRange &Loc) {
  bool Inserted = Functions.insert({F, Loc}).second;
  if (Inserted)
    FunctionsInverse.insert(Loc.Start, Loc.End, F);
  return Inserted;
}

bool AsmParserContext::addBlockLocation(BasicBlock *BB,
                                        const FileLocRange &Loc) {
  bool Inserted = Blocks.insert({BB, Loc}).second;
  if (Inserted)
    BlocksInverse.insert(Loc.Start, Loc.End, BB);
  return Inserted;
}

bool AsmParserContext::addInstructionOrArgumentLocation(
    Value *IA, const FileLocRange &Loc) {
  assert(isa<Instruction>(IA) || isa<Argument>(IA));
  bool Inserted = InstructionsAndArguments.insert({IA, Loc}).second;
  if (Inserted)
    InstructionsAndArgumentsInverse.insert(Loc.Start, Loc.End, IA);
  return Inserted;
}

bool AsmParserContext::addValueReferenceAtLocation(Value *V,
                                                   const FileLocRange &Loc) {
  ReferencedValues.insert(Loc.Start, Loc.End, V);
  return true;
}

} // namespace llvm