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/CodeGen/Register.h"
21 #include "llvm/IR/BasicBlock.h"
22 #include "llvm/IR/DebugLoc.h"
23 #include <functional>
24 #include <type_traits>
25 #include <utility>
26 
27 
28 namespace llvm {
29  class Function;
30  class MachineBasicBlock;
31  class MachineFunction;
32  class MachineInstr;
33  class TargetInstrInfo;
34  class TargetLowering;
35 
37  // Some useful objects to reduce the number of function arguments needed.
38  MachineFunction *MF;
39  const Function *Fn;
40  const TargetLowering *TLI;
41  const TargetInstrInfo *TII;
42 
43  /// A map from swifterror value in a basic block to the virtual register it is
44  /// currently represented by.
46  VRegDefMap;
47 
48  /// A list of upward exposed vreg uses that need to be satisfied by either a
49  /// copy def or a phi node at the beginning of the basic block representing
50  /// the predecessor(s) swifterror value.
52  VRegUpwardsUse;
53 
54  /// A map from instructions that define/use a swifterror value to the virtual
55  /// register that represents that def/use.
57  VRegDefUses;
58 
59  /// The swifterror argument of the current function.
60  const Value *SwiftErrorArg;
61 
63  /// A function can only have a single swifterror argument. And if it does
64  /// have a swifterror argument, it must be the first entry in
65  /// SwiftErrorVals.
66  SwiftErrorValues SwiftErrorVals;
67 
68 public:
69  /// Initialize data structures for specified new function.
70  void setFunction(MachineFunction &MF);
71 
72  /// Get the (unique) function argument that was marked swifterror, or nullptr
73  /// if this function has no swifterror args.
74  const Value *getFunctionArg() const {
75  return SwiftErrorArg;
76  }
77 
78  /// Get or create the swifterror value virtual register in
79  /// VRegDefMap for this basic block.
81 
82  /// Set the swifterror virtual register in the VRegDefMap for this
83  /// basic block.
84  void setCurrentVReg(const MachineBasicBlock *MBB, const Value *, Register);
85 
86  /// Get or create the swifterror value virtual register for a def of a
87  /// swifterror by an instruction.
89  const Value *);
90 
91  /// Get or create the swifterror value virtual register for a use of a
92  /// swifterror by an instruction.
94  const Value *);
95 
96  /// Create initial definitions of swifterror values in the entry block of the
97  /// current function.
99 
100  /// Propagate assigned swifterror vregs through a function, synthesizing PHI
101  /// nodes when needed to maintain consistency.
102  void propagateVRegs();
103 
106 };
107 
108 }
109 
110 #endif
void setCurrentVReg(const MachineBasicBlock *MBB, const Value *, Register)
Set the swifterror virtual register in the VRegDefMap for this basic block.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
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.
Register getOrCreateVRegUseAt(const Instruction *, const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register for a use of a swifterror by an instruction...
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...
Register getOrCreateVRegDefAt(const Instruction *, const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register for a def of a swifterror by an instruction...
TargetInstrInfo - Interface to description of machine instruction set.
Register getOrCreateVReg(const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register in VRegDefMap for this basic block.
LLVM Value Representation.
Definition: Value.h:72
void propagateVRegs()
Propagate assigned swifterror vregs through a function, synthesizing PHI nodes when needed to maintai...
Wrapper class representing virtual and physical registers.
Definition: Register.h:18