//===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// #ifndef LLVM_ASMPARSER_ASMPARSERCONTEXT_H #define LLVM_ASMPARSER_ASMPARSERCONTEXT_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/IntervalMap.h" #include "llvm/AsmParser/FileLoc.h" #include "llvm/IR/Value.h" #include namespace llvm { class BasicBlock; /// Registry of file location information for LLVM IR constructs. /// /// This class provides access to the file location information /// for various LLVM IR constructs. Currently, it supports Function, /// BasicBlock and Instruction locations. /// /// When available, it can answer queries about what is at a given /// file location, as well as where in a file a given IR construct /// is. /// /// This information is optionally emitted by the LLParser while /// it reads LLVM textual IR. class AsmParserContext { using FMap = IntervalMap::LeafSize, IntervalMapHalfOpenInfo>; DenseMap Functions; FMap::Allocator FAllocator; FMap FunctionsInverse = FMap(FAllocator); DenseMap Blocks; using BBMap = IntervalMap::LeafSize, IntervalMapHalfOpenInfo>; BBMap::Allocator BBAllocator; BBMap BlocksInverse = BBMap(BBAllocator); DenseMap InstructionsAndArguments; using VMap = IntervalMap::LeafSize, IntervalMapHalfOpenInfo>; VMap::Allocator VAllocator; VMap InstructionsAndArgumentsInverse = VMap(VAllocator); VMap ReferencedValues = VMap(VAllocator); public: LLVM_ABI std::optional getFunctionLocation(const Function *) const; LLVM_ABI std::optional getBlockLocation(const BasicBlock *) const; LLVM_ABI std::optional getInstructionOrArgumentLocation(const Value *) const; /// Get the function at the requested location range. /// If no single function occupies the queried range, or the record is /// missing, a nullptr is returned. LLVM_ABI Function *getFunctionAtLocation(const FileLocRange &) const; /// Get the function at the requested location. /// If no function occupies the queried location, or the record is missing, a /// nullptr is returned. LLVM_ABI Function *getFunctionAtLocation(const FileLoc &) const; /// Get the block at the requested location range. /// If no single block occupies the queried range, or the record is missing, a /// nullptr is returned. LLVM_ABI BasicBlock *getBlockAtLocation(const FileLocRange &) const; /// Get the block at the requested location. /// If no block occupies the queried location, or the record is missing, a /// nullptr is returned. LLVM_ABI BasicBlock *getBlockAtLocation(const FileLoc &) const; /// Get the instruction or function argument at the requested location range. /// If no single instruction occupies the queried range, or the record is /// missing, a nullptr is returned. LLVM_ABI Value * getInstructionOrArgumentAtLocation(const FileLocRange &) const; /// Get the instruction or function argument at the requested location. /// If no instruction occupies the queried location, or the record is missing, /// a nullptr is returned. LLVM_ABI Value *getInstructionOrArgumentAtLocation(const FileLoc &) const; /// Get value referenced at the requested location. /// If no value occupies the queried location, or the record is missing, /// a nullptr is returned. LLVM_ABI Value *getValueReferencedAtLocation(const FileLoc &) const; /// Get value referenced at the requested location range. /// If no value occupies the queried location, or the record is missing, /// a nullptr is returned. LLVM_ABI Value *getValueReferencedAtLocation(const FileLocRange &) const; LLVM_ABI bool addFunctionLocation(Function *, const FileLocRange &); LLVM_ABI bool addBlockLocation(BasicBlock *, const FileLocRange &); LLVM_ABI bool addInstructionOrArgumentLocation(Value *, const FileLocRange &); LLVM_ABI bool addValueReferenceAtLocation(Value *, const FileLocRange &); }; } // namespace llvm #endif