luau/CodeGen/src/IrLoweringX64.h
Arseny Kapoulkine 0d1db6a0b0 CodeGen: Optimize vandps for X64 when the source is computed
With the TAG_VECTOR change, we can now confidently distinguish cases when the .w component
contains TVECTOR tag from cases where it doesn't: loads and tag ops produce the tag, whereas
other instructions don't.

We now take advantage of this fact and only apply vandps with a mask when we need to.

It would be possible to use a positive filter (explicitly checking for source coming from ADD_VEC
et al), but there are more instructions to check this way and this is purely an optimization so
it is allowed to be conservative (as in, the cost of a mistake here is a potential slowdown,
not a correctness issue).
2024-02-26 10:38:28 -08:00

101 lines
2.4 KiB
C++

// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once
#include "Luau/AssemblyBuilderX64.h"
#include "Luau/DenseHash.h"
#include "Luau/IrData.h"
#include "Luau/IrRegAllocX64.h"
#include "IrValueLocationTracking.h"
#include <vector>
struct Proto;
namespace Luau
{
namespace CodeGen
{
struct ModuleHelpers;
struct AssemblyOptions;
struct LoweringStats;
namespace X64
{
struct IrLoweringX64
{
IrLoweringX64(AssemblyBuilderX64& build, ModuleHelpers& helpers, IrFunction& function, LoweringStats* stats);
void lowerInst(IrInst& inst, uint32_t index, const IrBlock& next);
void finishBlock(const IrBlock& curr, const IrBlock& next);
void finishFunction();
bool hasError() const;
bool isFallthroughBlock(const IrBlock& target, const IrBlock& next);
void jumpOrFallthrough(IrBlock& target, const IrBlock& next);
Label& getTargetLabel(IrOp op, Label& fresh);
void finalizeTargetLabel(IrOp op, Label& fresh);
void jumpOrAbortOnUndef(ConditionX64 cond, IrOp target, const IrBlock& next);
void jumpOrAbortOnUndef(IrOp target, const IrBlock& next);
void storeDoubleAsFloat(OperandX64 dst, IrOp src);
// Operand data lookup helpers
OperandX64 memRegDoubleOp(IrOp op);
OperandX64 memRegUintOp(IrOp op);
OperandX64 memRegTagOp(IrOp op);
RegisterX64 regOp(IrOp op);
OperandX64 bufferAddrOp(IrOp bufferOp, IrOp indexOp);
RegisterX64 vecOp(IrOp op, ScopedRegX64& tmp);
IrConst constOp(IrOp op) const;
uint8_t tagOp(IrOp op) const;
int intOp(IrOp op) const;
unsigned uintOp(IrOp op) const;
double doubleOp(IrOp op) const;
IrBlock& blockOp(IrOp op) const;
Label& labelOp(IrOp op) const;
OperandX64 vectorAndMaskOp();
OperandX64 vectorOrMaskOp();
struct InterruptHandler
{
Label self;
unsigned int pcpos;
Label next;
};
struct ExitHandler
{
Label self;
unsigned int pcpos;
};
AssemblyBuilderX64& build;
ModuleHelpers& helpers;
IrFunction& function;
LoweringStats* stats = nullptr;
IrRegAllocX64 regs;
IrValueLocationTracking valueTracker;
std::vector<InterruptHandler> interruptHandlers;
std::vector<ExitHandler> exitHandlers;
DenseHashMap<uint32_t, uint32_t> exitHandlerMap;
OperandX64 vectorAndMask = noreg;
OperandX64 vectorOrMask = noreg;
};
} // namespace X64
} // namespace CodeGen
} // namespace Luau