2014-04-02 17:03:43 +08:00
|
|
|
//===-- ARMOptimizeBarriersPass - two DMBs without a memory access in between,
|
|
|
|
//removed one -===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===------------------------------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARM.h"
|
|
|
|
#include "ARMInstrInfo.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "ARMMachineFunctionInfo.h"
|
2014-04-02 17:03:43 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "double barriers"
|
|
|
|
|
2014-04-02 17:03:43 +08:00
|
|
|
STATISTIC(NumDMBsRemoved, "Number of DMBs removed");
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class ARMOptimizeBarriersPass : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
ARMOptimizeBarriersPass() : MachineFunctionPass(ID) {}
|
|
|
|
|
2014-04-29 15:58:41 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &Fn) override;
|
2014-04-02 17:03:43 +08:00
|
|
|
|
2016-04-05 01:09:25 +08:00
|
|
|
MachineFunctionProperties getRequiredProperties() const override {
|
|
|
|
return MachineFunctionProperties().set(
|
2016-08-25 09:27:13 +08:00
|
|
|
MachineFunctionProperties::Property::NoVRegs);
|
2016-04-05 01:09:25 +08:00
|
|
|
}
|
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override { return "optimise barriers pass"; }
|
2014-04-02 17:03:43 +08:00
|
|
|
};
|
|
|
|
char ARMOptimizeBarriersPass::ID = 0;
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2014-04-02 17:03:43 +08:00
|
|
|
|
|
|
|
// Returns whether the instruction can safely move past a DMB instruction
|
|
|
|
// The current implementation allows this iif MI does not have any possible
|
|
|
|
// memory access
|
|
|
|
static bool CanMovePastDMB(const MachineInstr *MI) {
|
|
|
|
return !(MI->mayLoad() ||
|
|
|
|
MI->mayStore() ||
|
|
|
|
MI->hasUnmodeledSideEffects() ||
|
|
|
|
MI->isCall() ||
|
|
|
|
MI->isReturn());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ARMOptimizeBarriersPass::runOnMachineFunction(MachineFunction &MF) {
|
2016-04-26 06:01:04 +08:00
|
|
|
if (skipFunction(*MF.getFunction()))
|
|
|
|
return false;
|
|
|
|
|
2014-04-02 17:03:43 +08:00
|
|
|
// Vector to store the DMBs we will remove after the first iteration
|
|
|
|
std::vector<MachineInstr *> ToRemove;
|
|
|
|
// DMBType is the Imm value of the first operand. It determines whether it's a
|
|
|
|
// DMB ish, dmb sy, dmb osh, etc
|
|
|
|
int64_t DMBType = -1;
|
|
|
|
|
|
|
|
// Find a dmb. If we can move it until the next dmb, tag the second one for
|
|
|
|
// removal
|
|
|
|
for (auto &MBB : MF) {
|
|
|
|
// Will be true when we have seen a DMB, and not seen any instruction since
|
|
|
|
// that cannot move past a DMB
|
|
|
|
bool IsRemovableNextDMB = false;
|
|
|
|
for (auto &MI : MBB) {
|
|
|
|
if (MI.getOpcode() == ARM::DMB) {
|
|
|
|
if (IsRemovableNextDMB) {
|
|
|
|
// If the Imm of this DMB is the same as that of the last DMB, we can
|
|
|
|
// tag this second DMB for removal
|
|
|
|
if (MI.getOperand(0).getImm() == DMBType) {
|
|
|
|
ToRemove.push_back(&MI);
|
|
|
|
} else {
|
|
|
|
// If it has a different DMBType, we cannot remove it, but will scan
|
|
|
|
// for the next DMB, recording this DMB's type as last seen DMB type
|
|
|
|
DMBType = MI.getOperand(0).getImm();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// After we see a DMB, a next one is removable
|
|
|
|
IsRemovableNextDMB = true;
|
|
|
|
DMBType = MI.getOperand(0).getImm();
|
|
|
|
}
|
|
|
|
} else if (!CanMovePastDMB(&MI)) {
|
|
|
|
// If we find an instruction unable to pass past a DMB, a next DMB is
|
|
|
|
// not removable
|
|
|
|
IsRemovableNextDMB = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-09 02:02:51 +08:00
|
|
|
bool Changed = false;
|
2014-04-02 17:03:43 +08:00
|
|
|
// Remove the tagged DMB
|
|
|
|
for (auto MI : ToRemove) {
|
|
|
|
MI->eraseFromParent();
|
|
|
|
++NumDMBsRemoved;
|
2017-05-09 02:02:51 +08:00
|
|
|
Changed = true;
|
2014-04-02 17:03:43 +08:00
|
|
|
}
|
|
|
|
|
2017-05-09 02:02:51 +08:00
|
|
|
return Changed;
|
2014-04-02 17:03:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// createARMOptimizeBarriersPass - Returns an instance of the remove double
|
|
|
|
/// barriers
|
|
|
|
/// pass.
|
|
|
|
FunctionPass *llvm::createARMOptimizeBarriersPass() {
|
|
|
|
return new ARMOptimizeBarriersPass();
|
|
|
|
}
|