LLVM  14.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 <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
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::Function
Definition: Function.h:62
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:97
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition: TargetLowering.h:3254
llvm::Instruction
Definition: Instruction.h:45
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:259
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
BasicBlock.h
llvm::DenseMap
Definition: DenseMap.h:714
llvm::SwiftErrorValueTracking
Definition: SwiftErrorValueTracking.h:36
llvm::SwiftErrorValueTracking::setFunction
void setFunction(MachineFunction &MF)
Initialize data structures for specified new function.
Definition: SwiftErrorValueTracking.cpp:79
llvm::MachineFunction
Definition: MachineFunction.h:241
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:74
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::BasicBlock::const_iterator
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:91
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