#include "llvm/CodeGen/ComplexDeinterleavingPass.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/InitializePasses.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Utils/Local.h"
#include <algorithm>
usingnamespacellvm;
usingnamespacePatternMatch;
#define DEBUG_TYPE …
STATISTIC(NumComplexTransformations, "Amount of complex patterns transformed");
static cl::opt<bool> ComplexDeinterleavingEnabled(
"enable-complex-deinterleaving",
cl::desc("Enable generation of complex instructions"), cl::init(true),
cl::Hidden);
static bool isInterleavingMask(ArrayRef<int> Mask);
static bool isDeinterleavingMask(ArrayRef<int> Mask);
static bool isNeg(Value *V);
static Value *getNegOperand(Value *V);
namespace {
class ComplexDeinterleavingLegacyPass : public FunctionPass { … };
class ComplexDeinterleavingGraph;
struct ComplexDeinterleavingCompositeNode { … };
class ComplexDeinterleavingGraph { … };
class ComplexDeinterleaving { … };
}
char ComplexDeinterleavingLegacyPass::ID = …;
INITIALIZE_PASS_BEGIN(ComplexDeinterleavingLegacyPass, DEBUG_TYPE,
"Complex Deinterleaving", false, false)
INITIALIZE_PASS_END(ComplexDeinterleavingLegacyPass, DEBUG_TYPE,
"Complex Deinterleaving", false, false)
PreservedAnalyses ComplexDeinterleavingPass::run(Function &F,
FunctionAnalysisManager &AM) { … }
FunctionPass *llvm::createComplexDeinterleavingPass(const TargetMachine *TM) { … }
bool ComplexDeinterleavingLegacyPass::runOnFunction(Function &F) { … }
bool ComplexDeinterleaving::runOnFunction(Function &F) { … }
static bool isInterleavingMask(ArrayRef<int> Mask) { … }
static bool isDeinterleavingMask(ArrayRef<int> Mask) { … }
bool isNeg(Value *V) { … }
Value *getNegOperand(Value *V) { … }
bool ComplexDeinterleaving::evaluateBasicBlock(BasicBlock *B) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifyNodeWithImplicitAdd(
Instruction *Real, Instruction *Imag,
std::pair<Value *, Value *> &PartialMatch) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifyPartialMul(Instruction *Real,
Instruction *Imag) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifyAdd(Instruction *Real, Instruction *Imag) { … }
static bool isInstructionPairAdd(Instruction *A, Instruction *B) { … }
static bool isInstructionPairMul(Instruction *A, Instruction *B) { … }
static bool isInstructionPotentiallySymmetric(Instruction *I) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifySymmetricOperation(Instruction *Real,
Instruction *Imag) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifyNode(Value *R, Value *I) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifyReassocNodes(Instruction *Real,
Instruction *Imag) { … }
bool ComplexDeinterleavingGraph::collectPartialMuls(
const std::vector<Product> &RealMuls, const std::vector<Product> &ImagMuls,
std::vector<PartialMulCandidate> &PartialMulCandidates) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifyMultiplications(
std::vector<Product> &RealMuls, std::vector<Product> &ImagMuls,
NodePtr Accumulator = nullptr) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifyAdditions(
std::list<Addend> &RealAddends, std::list<Addend> &ImagAddends,
std::optional<FastMathFlags> Flags, NodePtr Accumulator = nullptr) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::extractPositiveAddend(
std::list<Addend> &RealAddends, std::list<Addend> &ImagAddends) { … }
bool ComplexDeinterleavingGraph::identifyNodes(Instruction *RootI) { … }
bool ComplexDeinterleavingGraph::collectPotentialReductions(BasicBlock *B) { … }
void ComplexDeinterleavingGraph::identifyReductionNodes() { … }
bool ComplexDeinterleavingGraph::checkNodes() { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifyRoot(Instruction *RootI) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifyDeinterleave(Instruction *Real,
Instruction *Imag) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifySplat(Value *R, Value *I) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifyPHINode(Instruction *Real,
Instruction *Imag) { … }
ComplexDeinterleavingGraph::NodePtr
ComplexDeinterleavingGraph::identifySelectNode(Instruction *Real,
Instruction *Imag) { … }
static Value *replaceSymmetricNode(IRBuilderBase &B, unsigned Opcode,
std::optional<FastMathFlags> Flags,
Value *InputA, Value *InputB) { … }
Value *ComplexDeinterleavingGraph::replaceNode(IRBuilderBase &Builder,
RawNodePtr Node) { … }
void ComplexDeinterleavingGraph::processReductionOperation(
Value *OperationReplacement, RawNodePtr Node) { … }
void ComplexDeinterleavingGraph::replaceNodes() { … }