/
SelectVariableNames.h
41 lines (31 loc) · 1.23 KB
/
SelectVariableNames.h
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
#ifndef INCLUDE_ANALYSIS_SELECTVARIABLENAMES_SELECTVARIABLENAMES_H_
#define INCLUDE_ANALYSIS_SELECTVARIABLENAMES_SELECTVARIABLENAMES_H_
#include <string>
#include "llvm/include/llvm/ADT/DenseMap.h" // from @llvm-project
#include "mlir/include/mlir/IR/Operation.h" // from @llvm-project
#include "mlir/include/mlir/IR/Value.h" // from @llvm-project
namespace mlir {
namespace heir {
class SelectVariableNames {
public:
SelectVariableNames(Operation *op);
~SelectVariableNames() = default;
/// Return the name assigned to the given value, or an empty string if the
/// value was not assigned a name (suggesting the value was not in the IR
/// tree that this class was constructed with).
std::string getNameForValue(Value value) const {
assert(variableNames.contains(value));
return prefix + std::to_string(variableNames.lookup(value));
}
// Return the unique integer assigned to a given value.
int getIntForValue(Value value) const {
assert(variableNames.contains(value));
return variableNames.lookup(value);
}
private:
llvm::DenseMap<Value, int> variableNames;
std::string prefix{"v"};
};
} // namespace heir
} // namespace mlir
#endif // INCLUDE_ANALYSIS_SELECTVARIABLENAMES_SELECTVARIABLENAMES_H_