LLVM  9.0.0svn
SwiftErrorValueTracking.h
Go to the documentation of this file.
1 //===- SwiftErrorValueTracking.h - Track swifterror VReg vals --*- C++ -*--===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This implements a limited mem2reg-like analysis to promote uses of function
10 // arguments and allocas marked with swiftalloc from memory into virtual
11 // registers tracked by this class.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef SWIFTERRORVALUETRACKING_H
16 #define SWIFTERRORVALUETRACKING_H
17 
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/IR/BasicBlock.h"
21 #include "llvm/IR/DebugLoc.h"
22 #include <functional>
23 #include <type_traits>
24 #include <utility>
25 
26 
27 namespace llvm {
28  class Function;
29  class MachineBasicBlock;
30  class MachineFunction;
31  class MachineInstr;
32  class TargetInstrInfo;
33  class TargetLowering;
34 
36  // Some useful objects to reduce the number of function arguments needed.
37  MachineFunction *MF;
38  const Function *Fn;
39  const TargetLowering *TLI;
40  const TargetInstrInfo *TII;
41 
42  /// A map from swifterror value in a basic block to the virtual register it is
43  /// currently represented by.
45  VRegDefMap;
46 
47  /// A list of upward exposed vreg uses that need to be satisfied by either a
48  /// copy def or a phi node at the beginning of the basic block representing
49  /// the predecessor(s) swifterror value.
51  VRegUpwardsUse;
52 
53  /// A map from instructions that define/use a swifterror value to the virtual
54  /// register that represents that def/use.
56  VRegDefUses;
57 
58  /// The swifterror argument of the current function.
59  const Value *SwiftErrorArg;
60 
62  /// A function can only have a single swifterror argument. And if it does
63  /// have a swifterror argument, it must be the first entry in
64  /// SwiftErrorVals.
65  SwiftErrorValues SwiftErrorVals;
66 
67 public:
68  /// Initialize data structures for specified new function.
69  void setFunction(MachineFunction &MF);
70 
71  /// Get the (unique) function argument that was marked swifterror, or nullptr
72  /// if this function has no swifterror args.
73  const Value *getFunctionArg() const {
74  return SwiftErrorArg;
75  }
76 
77  /// Get or create the swifterror value virtual register in
78  /// VRegDefMap for this basic block.
79  unsigned getOrCreateVReg(const MachineBasicBlock *, const Value *);
80 
81  /// Set the swifterror virtual register in the VRegDefMap for this
82  /// basic block.
83  void setCurrentVReg(const MachineBasicBlock *MBB, const Value *, unsigned);
84 
85  /// Get or create the swifterror value virtual register for a def of a
86  /// swifterror by an instruction.
87  unsigned getOrCreateVRegDefAt(const Instruction *, const MachineBasicBlock *,
88  const Value *);
89 
90  /// Get or create the swifterror value virtual register for a use of a
91  /// swifterror by an instruction.
92  unsigned getOrCreateVRegUseAt(const Instruction *, const MachineBasicBlock *,
93  const Value *);
94 
95  /// Create initial definitions of swifterror values in the entry block of the
96  /// current function.
98 
99  /// Propagate assigned swifterror vregs through a function, synthesizing PHI
100  /// nodes when needed to maintain consistency.
101  void propagateVRegs();
102 
105 };
106 
107 }
108 
109 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:23
unsigned getOrCreateVRegUseAt(const Instruction *, const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register for a use of a swifterror by an instruction...
void setCurrentVReg(const MachineBasicBlock *MBB, const Value *, unsigned)
Set the swifterror virtual register in the VRegDefMap for this basic block.
unsigned getOrCreateVReg(const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register in VRegDefMap for this basic block.
A debug info location.
Definition: DebugLoc.h:33
void preassignVRegs(MachineBasicBlock *MBB, BasicBlock::const_iterator Begin, BasicBlock::const_iterator End)
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:90
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
void setFunction(MachineFunction &MF)
Initialize data structures for specified new function.
const Value * getFunctionArg() const
Get the (unique) function argument that was marked swifterror, or nullptr if this function has no swi...
bool createEntriesInEntryBlock(DebugLoc DbgLoc)
Create initial definitions of swifterror values in the entry block of the current function...
TargetInstrInfo - Interface to description of machine instruction set.
unsigned getOrCreateVRegDefAt(const Instruction *, const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register for a def of a swifterror by an instruction...
LLVM Value Representation.
Definition: Value.h:72
void propagateVRegs()
Propagate assigned swifterror vregs through a function, synthesizing PHI nodes when needed to maintai...