2017-09-12 01:00:48 +02:00
|
|
|
//===- MachineSSAUpdater.h - Unstructured SSA Update Tool -------*- C++ -*-===//
|
2009-12-02 23:02:52 +01:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// 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
|
2009-12-02 23:02:52 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the MachineSSAUpdater class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINESSAUPDATER_H
|
|
|
|
#define LLVM_CODEGEN_MACHINESSAUPDATER_H
|
|
|
|
|
2020-04-08 19:50:35 +02:00
|
|
|
#include "llvm/CodeGen/Register.h"
|
|
|
|
|
2009-12-02 23:02:52 +01:00
|
|
|
namespace llvm {
|
2017-09-12 01:00:48 +02:00
|
|
|
|
|
|
|
class MachineBasicBlock;
|
|
|
|
class MachineFunction;
|
|
|
|
class MachineInstr;
|
|
|
|
class MachineOperand;
|
|
|
|
class MachineRegisterInfo;
|
|
|
|
class TargetInstrInfo;
|
|
|
|
class TargetRegisterClass;
|
|
|
|
template<typename T> class SmallVectorImpl;
|
|
|
|
template<typename T> class SSAUpdaterTraits;
|
2009-12-02 23:02:52 +01:00
|
|
|
|
2009-12-03 03:31:43 +01:00
|
|
|
/// MachineSSAUpdater - This class updates SSA form for a set of virtual
|
|
|
|
/// registers defined in multiple blocks. This is used when code duplication
|
|
|
|
/// or another unstructured transformation wants to rewrite a set of uses of one
|
|
|
|
/// vreg with uses of a set of vregs.
|
2009-12-02 23:02:52 +01:00
|
|
|
class MachineSSAUpdater {
|
2010-05-05 01:18:19 +02:00
|
|
|
friend class SSAUpdaterTraits<MachineSSAUpdater>;
|
2010-04-26 19:40:49 +02:00
|
|
|
|
|
|
|
private:
|
2009-12-02 23:02:52 +01:00
|
|
|
/// AvailableVals - This keeps track of which value to use on a per-block
|
|
|
|
/// basis. When we insert PHI nodes, we keep track of them here.
|
2020-04-08 19:50:35 +02:00
|
|
|
//typedef DenseMap<MachineBasicBlock*, Register> AvailableValsTy;
|
2017-09-12 01:00:48 +02:00
|
|
|
void *AV = nullptr;
|
2009-12-02 23:02:52 +01:00
|
|
|
|
2009-12-03 03:31:43 +01:00
|
|
|
/// VRC - Register class of the current virtual register.
|
|
|
|
const TargetRegisterClass *VRC;
|
|
|
|
|
2009-12-02 23:02:52 +01:00
|
|
|
/// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI
|
|
|
|
/// nodes that it creates to the vector.
|
|
|
|
SmallVectorImpl<MachineInstr*> *InsertedPHIs;
|
2009-12-03 03:31:43 +01:00
|
|
|
|
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
MachineRegisterInfo *MRI;
|
2017-09-12 01:00:48 +02:00
|
|
|
|
2009-12-02 23:02:52 +01:00
|
|
|
public:
|
|
|
|
/// MachineSSAUpdater constructor. If InsertedPHIs is specified, it will be
|
|
|
|
/// filled in with all PHI Nodes created by rewriting.
|
2009-12-03 03:31:43 +01:00
|
|
|
explicit MachineSSAUpdater(MachineFunction &MF,
|
2018-07-16 20:51:40 +02:00
|
|
|
SmallVectorImpl<MachineInstr*> *NewPHI = nullptr);
|
2017-09-12 01:00:48 +02:00
|
|
|
MachineSSAUpdater(const MachineSSAUpdater &) = delete;
|
|
|
|
MachineSSAUpdater &operator=(const MachineSSAUpdater &) = delete;
|
2009-12-02 23:02:52 +01:00
|
|
|
~MachineSSAUpdater();
|
|
|
|
|
|
|
|
/// Initialize - Reset this object to get ready for a new set of SSA
|
|
|
|
/// updates.
|
2020-04-08 19:50:35 +02:00
|
|
|
void Initialize(Register V);
|
2020-05-18 16:28:34 +02:00
|
|
|
void Initialize(const TargetRegisterClass *RC);
|
2009-12-02 23:02:52 +01:00
|
|
|
|
|
|
|
/// AddAvailableValue - Indicate that a rewritten value is available at the
|
|
|
|
/// end of the specified block with the specified value.
|
2020-04-08 19:50:35 +02:00
|
|
|
void AddAvailableValue(MachineBasicBlock *BB, Register V);
|
2009-12-02 23:02:52 +01:00
|
|
|
|
|
|
|
/// HasValueForBlock - Return true if the MachineSSAUpdater already has a
|
|
|
|
/// value for the specified block.
|
|
|
|
bool HasValueForBlock(MachineBasicBlock *BB) const;
|
|
|
|
|
|
|
|
/// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
|
|
|
|
/// live at the end of the specified block.
|
2020-04-08 19:50:35 +02:00
|
|
|
Register GetValueAtEndOfBlock(MachineBasicBlock *BB);
|
2009-12-02 23:02:52 +01:00
|
|
|
|
|
|
|
/// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
|
|
|
|
/// is live in the middle of the specified block.
|
|
|
|
///
|
|
|
|
/// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one
|
|
|
|
/// important case: if there is a definition of the rewritten value after the
|
|
|
|
/// 'use' in BB. Consider code like this:
|
|
|
|
///
|
|
|
|
/// X1 = ...
|
|
|
|
/// SomeBB:
|
|
|
|
/// use(X)
|
|
|
|
/// X2 = ...
|
|
|
|
/// br Cond, SomeBB, OutBB
|
|
|
|
///
|
|
|
|
/// In this case, there are two values (X1 and X2) added to the AvailableVals
|
|
|
|
/// set by the client of the rewriter, and those values are both live out of
|
|
|
|
/// their respective blocks. However, the use of X happens in the *middle* of
|
|
|
|
/// a block. Because of this, we need to insert a new PHI node in SomeBB to
|
|
|
|
/// merge the appropriate values, and this value isn't live out of the block.
|
2020-04-08 19:50:35 +02:00
|
|
|
Register GetValueInMiddleOfBlock(MachineBasicBlock *BB);
|
2009-12-02 23:02:52 +01:00
|
|
|
|
|
|
|
/// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes,
|
|
|
|
/// which use their value in the corresponding predecessor. Note that this
|
|
|
|
/// will not work if the use is supposed to be rewritten to a value defined in
|
|
|
|
/// the same block as the use, but above it. Any 'AddAvailableValue's added
|
|
|
|
/// for the use's block will be considered to be below it.
|
2009-12-03 03:31:43 +01:00
|
|
|
void RewriteUse(MachineOperand &U);
|
2009-12-02 23:02:52 +01:00
|
|
|
|
|
|
|
private:
|
2020-04-08 19:50:35 +02:00
|
|
|
Register GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
|
2009-12-02 23:02:52 +01:00
|
|
|
};
|
|
|
|
|
2017-09-12 01:00:48 +02:00
|
|
|
} // end namespace llvm
|
2009-12-02 23:02:52 +01:00
|
|
|
|
2017-09-12 01:00:48 +02:00
|
|
|
#endif // LLVM_CODEGEN_MACHINESSAUPDATER_H
|