LLVM 20.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"
21#include "llvm/IR/BasicBlock.h"
22#include "llvm/IR/DebugLoc.h"
23#include <utility>
24
25
26namespace 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.
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
66public:
67 /// Initialize data structures for specified new function.
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
MachineBasicBlock & MBB
This file defines the DenseMap class.
bool End
Definition: ELF_riscv.cpp:480
This file defines the SmallVector class.
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:178
A debug info location.
Definition: DebugLoc.h:33
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
bool createEntriesInEntryBlock(DebugLoc DbgLoc)
Create initial definitions of swifterror values in the entry block of the current function.
void setFunction(MachineFunction &MF)
Initialize data structures for specified new function.
Register getOrCreateVReg(const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register in VRegDefMap for this basic block.
void setCurrentVReg(const MachineBasicBlock *MBB, const Value *, Register)
Set the swifterror virtual register in the VRegDefMap for this basic block.
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.
void preassignVRegs(MachineBasicBlock *MBB, BasicBlock::const_iterator Begin, BasicBlock::const_iterator End)
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.
const Value * getFunctionArg() const
Get the (unique) function argument that was marked swifterror, or nullptr if this function has no swi...
void propagateVRegs()
Propagate assigned swifterror vregs through a function, synthesizing PHI nodes when needed to maintai...
TargetInstrInfo - Interface to description of machine instruction set.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18