2008-05-15 18:04:30 +08:00
|
|
|
//===-- Use.cpp - Implement the Use class ---------------------------------===//
|
2008-05-10 16:32:32 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2008-05-10 16:32:32 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-04 16:51:00 +08:00
|
|
|
#include "llvm/IR/Use.h"
|
2014-03-04 17:19:43 +08:00
|
|
|
#include "llvm/IR/User.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Value.h"
|
2012-03-26 22:04:17 +08:00
|
|
|
#include <new>
|
2008-05-10 16:32:32 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2008-05-14 06:51:52 +08:00
|
|
|
void Use::swap(Use &RHS) {
|
2014-03-04 17:00:15 +08:00
|
|
|
if (Val == RHS.Val)
|
|
|
|
return;
|
2008-05-14 06:51:52 +08:00
|
|
|
|
2014-03-04 17:00:15 +08:00
|
|
|
if (Val)
|
|
|
|
removeFromList();
|
2008-05-14 06:51:52 +08:00
|
|
|
|
2014-03-04 17:00:15 +08:00
|
|
|
Value *OldVal = Val;
|
|
|
|
if (RHS.Val) {
|
|
|
|
RHS.removeFromList();
|
|
|
|
Val = RHS.Val;
|
|
|
|
Val->addUse(*this);
|
|
|
|
} else {
|
2014-04-09 14:08:46 +08:00
|
|
|
Val = nullptr;
|
2014-03-04 17:00:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (OldVal) {
|
|
|
|
RHS.Val = OldVal;
|
|
|
|
RHS.Val->addUse(RHS);
|
|
|
|
} else {
|
2014-04-09 14:08:46 +08:00
|
|
|
RHS.Val = nullptr;
|
2008-05-14 06:51:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 17:19:43 +08:00
|
|
|
unsigned Use::getOperandNo() const {
|
|
|
|
return this - getUser()->op_begin();
|
|
|
|
}
|
|
|
|
|
2008-05-10 16:32:32 +08:00
|
|
|
void Use::zap(Use *Start, const Use *Stop, bool del) {
|
2011-01-16 23:30:52 +08:00
|
|
|
while (Start != Stop)
|
|
|
|
(--Stop)->~Use();
|
|
|
|
if (del)
|
2008-05-10 16:32:32 +08:00
|
|
|
::operator delete(Start);
|
|
|
|
}
|
|
|
|
|
2015-06-23 17:49:53 +08:00
|
|
|
} // End llvm namespace
|