[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / include / llvm / Support / SaveAndRestore.h
blob3c0333b7119a6f3b6c36bda3f46dfedb0ce5d171
1 //===-- SaveAndRestore.h - Utility -------------------------------*- 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 /// \file
10 /// This file provides utility classes that use RAII to save and restore
11 /// values.
12 ///
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_SAVEANDRESTORE_H
16 #define LLVM_SUPPORT_SAVEANDRESTORE_H
18 namespace llvm {
20 /// A utility class that uses RAII to save and restore the value of a variable.
21 template <typename T> struct SaveAndRestore {
22 SaveAndRestore(T &X) : X(X), OldValue(X) {}
23 SaveAndRestore(T &X, const T &NewValue) : X(X), OldValue(X) {
24 X = NewValue;
26 ~SaveAndRestore() { X = OldValue; }
27 T get() { return OldValue; }
29 private:
30 T &X;
31 T OldValue;
34 } // namespace llvm
36 #endif