LLVM  16.0.0git
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 LLVM_CODEGEN_SWIFTERRORVALUETRACKING_H
16 #define LLVM_CODEGEN_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 <utility>
24 
25 
26 namespace llvm {
27  class Function;
28  class MachineBasicBlock;
29  class MachineFunction;
30  class MachineInstr;
31  class TargetInstrInfo;
32  class TargetLowering;
33 
35  // Some useful objects to reduce the number of function arguments needed.
36  MachineFunction *MF;
37  const Function *Fn;
38  const TargetLowering *TLI;
39  const TargetInstrInfo *TII;
40 
41  /// A map from swifterror value in a basic block to the virtual register it is
42  /// currently represented by.
44  VRegDefMap;
45 
46  /// A list of upward exposed vreg uses that need to be satisfied by either a
47  /// copy def or a phi node at the beginning of the basic block representing
48  /// the predecessor(s) swifterror value.
50  VRegUpwardsUse;
51 
52  /// A map from instructions that define/use a swifterror value to the virtual
53  /// register that represents that def/use.
55  VRegDefUses;
56 
57  /// The swifterror argument of the current function.
58  const Value *SwiftErrorArg;
59 
61  /// A function can only have a single swifterror argument. And if it does
62  /// have a swifterror argument, it must be the first entry in
63  /// SwiftErrorVals.
64  SwiftErrorValues SwiftErrorVals;
65 
66 public:
67  /// Initialize data structures for specified new function.
68  void setFunction(MachineFunction &MF);
69 
70  /// Get the (unique) function argument that was marked swifterror, or nullptr
71  /// if this function has no swifterror args.
72  const Value *getFunctionArg() const {
73  return SwiftErrorArg;
74  }
75 
76  /// Get or create the swifterror value virtual register in
77  /// VRegDefMap for this basic block.
79 
80  /// Set the swifterror virtual register in the VRegDefMap for this
81  /// basic block.
82  void setCurrentVReg(const MachineBasicBlock *MBB, const Value *, Register);
83 
84  /// Get or create the swifterror value virtual register for a def of a
85  /// swifterror by an instruction.
87  const Value *);
88 
89  /// Get or create the swifterror value virtual register for a use of a
90  /// swifterror by an instruction.
92  const Value *);
93 
94  /// Create initial definitions of swifterror values in the entry block of the
95  /// current function.
97 
98  /// Propagate assigned swifterror vregs through a function, synthesizing PHI
99  /// nodes when needed to maintain consistency.
100  void propagateVRegs();
101 
104 };
105 
106 }
107 
108 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::Function
Definition: Function.h:60
llvm::SmallVector< const Value *, 1 >
llvm::SwiftErrorValueTracking::createEntriesInEntryBlock
bool createEntriesInEntryBlock(DebugLoc DbgLoc)
Create initial definitions of swifterror values in the entry block of the current function.
Definition: SwiftErrorValueTracking.cpp:115
llvm::SwiftErrorValueTracking::propagateVRegs
void propagateVRegs()
Propagate assigned swifterror vregs through a function, synthesizing PHI nodes when needed to maintai...
Definition: SwiftErrorValueTracking.cpp:147
DenseMap.h
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition: TargetInstrInfo.h:98
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition: TargetLowering.h:3490
llvm::Instruction
Definition: Instruction.h:42
llvm::SwiftErrorValueTracking::getOrCreateVRegUseAt
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.
Definition: SwiftErrorValueTracking.cpp:65
DebugLoc.h
llvm::SwiftErrorValueTracking::preassignVRegs
void preassignVRegs(MachineBasicBlock *MBB, BasicBlock::const_iterator Begin, BasicBlock::const_iterator End)
Definition: SwiftErrorValueTracking.cpp:258
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
BasicBlock.h
llvm::DenseMap
Definition: DenseMap.h:714
llvm::SwiftErrorValueTracking
Definition: SwiftErrorValueTracking.h:34
llvm::SwiftErrorValueTracking::setFunction
void setFunction(MachineFunction &MF)
Initialize data structures for specified new function.
Definition: SwiftErrorValueTracking.cpp:79
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::SwiftErrorValueTracking::getOrCreateVRegDefAt
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.
Definition: SwiftErrorValueTracking.cpp:50
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
SmallVector.h
Register.h
llvm::SwiftErrorValueTracking::getOrCreateVReg
Register getOrCreateVReg(const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register in VRegDefMap for this basic block.
Definition: SwiftErrorValueTracking.cpp:26
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::SwiftErrorValueTracking::getFunctionArg
const Value * getFunctionArg() const
Get the (unique) function argument that was marked swifterror, or nullptr if this function has no swi...
Definition: SwiftErrorValueTracking.h:72
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::BasicBlock::const_iterator
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:88
llvm::SwiftErrorValueTracking::setCurrentVReg
void setCurrentVReg(const MachineBasicBlock *MBB, const Value *, Register)
Set the swifterror virtual register in the VRegDefMap for this basic block.
Definition: SwiftErrorValueTracking.cpp:45