Skip to content

[CodeGen] Use SmallVector for FixedStackPSVs #91760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/PseudoSourceValueManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#ifndef LLVM_CODEGEN_PSEUDOSOURCEVALUEMANAGER_H
#define LLVM_CODEGEN_PSEUDOSOURCEVALUEMANAGER_H

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/CodeGen/PseudoSourceValue.h"
#include "llvm/IR/ValueMap.h"
#include <map>

namespace llvm {

Expand All @@ -27,7 +27,7 @@ class TargetMachine;
class PseudoSourceValueManager {
const TargetMachine &TM;
const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV;
std::map<int, std::unique_ptr<FixedStackPseudoSourceValue>> FSValues;
SmallVector<std::unique_ptr<FixedStackPseudoSourceValue>> FSValues;
StringMap<std::unique_ptr<const ExternalSymbolPseudoSourceValue>>
ExternalCallEntries;
ValueMap<const GlobalValue *,
Expand Down
7 changes: 6 additions & 1 deletion llvm/lib/CodeGen/PseudoSourceValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() {

const PseudoSourceValue *
PseudoSourceValueManager::getFixedStack(int FI) {
std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[FI];
// Frame index is often continuously positive, but can be negative. Use
// zig-zag encoding for dense index into FSValues vector.
unsigned Idx = (2 * unsigned(FI)) ^ (FI >> (sizeof(FI) * 8 - 1));
if (FSValues.size() <= Idx)
FSValues.resize(Idx + 1);
std::unique_ptr<FixedStackPseudoSourceValue> &V = FSValues[Idx];
if (!V)
V = std::make_unique<FixedStackPseudoSourceValue>(FI, TM);
return V.get();
Expand Down
Loading