[llvm] [SandboxVec][BottomUpVec] Implement InstrMaps (PR #122848)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 16 14:18:06 PST 2025
================
@@ -0,0 +1,77 @@
+//===- InstructionMaps.h ----------------------------------------*- C++ -*-===//
+//
+// 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_TRANSFORMS_VECTORIZE_SANDBOXVEC_PASSES_INSTRUCTIONMAPS_H
+#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVEC_PASSES_INSTRUCTIONMAPS_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/SandboxIR/Value.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm::sandboxir {
+
+/// Maps the original instructions to the vectorized instrs and the reverse.
+/// For now an original instr can only map to a single vector.
+class InstrMaps {
+ /// A map from the original values that got combined into vectors, to the
+ /// vector value(s).
+ DenseMap<Value *, Value *> OrigToVectorMap;
+ /// A map from the vector value to a map of the original value to its lane.
+ /// Please note that for constant vectors, there may multiple original values
+ /// with the same lane, as they may be coming from vectorizing different
+ /// original values.
+ DenseMap<Value *, DenseMap<Value *, unsigned>> VectorToOrigLaneMap;
+
+public:
+ /// \Returns all the vector value that we got from vectorizing \p Orig, or
+ /// nullptr if not found.
+ Value *getVectorForOrig(Value *Orig) const {
+ auto It = OrigToVectorMap.find(Orig);
+ return It != OrigToVectorMap.end() ? It->second : nullptr;
+ }
+ /// \Returns the lane of \p Orig before it got vectorized into \p Vec, or
+ /// nullopt if not found.
+ std::optional<int> getOrigLane(Value *Vec, Value *Orig) const {
----------------
vporpo wrote:
I will change it to optional<unsigned>.
https://github.com/llvm/llvm-project/pull/122848
More information about the llvm-commits
mailing list