llvm/llvm/lib/Target/Hexagon/HexagonPeephole.cpp

//===-- HexagonPeephole.cpp - Hexagon Peephole Optimiztions ---------------===//
//
// 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
//
// This peephole pass optimizes in the following cases.
// 1. Optimizes redundant sign extends for the following case
//    Transform the following pattern
//    %170 = SXTW %166
//    ...
//    %176 = COPY %170:isub_lo
//
//    Into
//    %176 = COPY %166
//
//  2. Optimizes redundant negation of predicates.
//     %15 = CMPGTrr %6, %2
//     ...
//     %16 = NOT_p killed %15
//     ...
//     JMP_c killed %16, <%bb.1>, implicit dead %pc
//
//     Into
//     %15 = CMPGTrr %6, %2;
//     ...
//     JMP_cNot killed %15, <%bb.1>, implicit dead %pc;
//
// Note: The peephole pass makes the instrucstions like
// %170 = SXTW %166 or %16 = NOT_p killed %15
// redundant and relies on some form of dead removal instructions, like
// DCE or DIE to actually eliminate them.

//===----------------------------------------------------------------------===//

#include "Hexagon.h"
#include "HexagonTargetMachine.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/IR/Constants.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include <algorithm>

usingnamespacellvm;

#define DEBUG_TYPE

static cl::opt<bool>
    DisableHexagonPeephole("disable-hexagon-peephole", cl::Hidden,
                           cl::desc("Disable Peephole Optimization"));

static cl::opt<bool> DisablePNotP("disable-hexagon-pnotp", cl::Hidden,
                                  cl::desc("Disable Optimization of PNotP"));

static cl::opt<bool>
    DisableOptSZExt("disable-hexagon-optszext", cl::Hidden, cl::init(true),
                    cl::desc("Disable Optimization of Sign/Zero Extends"));

static cl::opt<bool>
    DisableOptExtTo64("disable-hexagon-opt-ext-to-64", cl::Hidden,
                      cl::init(true),
                      cl::desc("Disable Optimization of extensions to i64."));

namespace llvm {
  FunctionPass *createHexagonPeephole();
  void initializeHexagonPeepholePass(PassRegistry&);
}

namespace {
  struct HexagonPeephole : public MachineFunctionPass {};
}

char HexagonPeephole::ID =;

INITIALIZE_PASS()

bool HexagonPeephole::runOnMachineFunction(MachineFunction &MF) {}

FunctionPass *llvm::createHexagonPeephole() {}