2016-12-08 06:06:02 +08:00
|
|
|
//===-- ConstantsContext.h - Constants-related Context Interals -*- C++ -*-===//
|
2009-08-05 06:55:26 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines various helper methods and classes used by
|
|
|
|
// LLVMContextImpl for creating and managing constants.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_IR_CONSTANTSCONTEXT_H
|
|
|
|
#define LLVM_LIB_IR_CONSTANTSCONTEXT_H
|
2009-08-05 06:55:26 +08:00
|
|
|
|
2016-12-08 06:06:02 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/DenseMapInfo.h"
|
2016-04-07 01:56:08 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2012-03-06 18:43:52 +08:00
|
|
|
#include "llvm/ADT/Hashing.h"
|
2016-12-08 06:06:02 +08:00
|
|
|
#include "llvm/ADT/None.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-05-16 05:57:41 +08:00
|
|
|
#include "llvm/IR/Constant.h"
|
2016-12-08 06:06:02 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/InlineAsm.h"
|
2016-12-08 06:06:02 +08:00
|
|
|
#include "llvm/IR/Instruction.h"
|
|
|
|
#include "llvm/IR/OperandTraits.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
2010-01-05 09:34:26 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-08-05 06:55:26 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-23 12:44:11 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2016-12-08 06:06:02 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <utility>
|
2009-08-05 06:55:26 +08:00
|
|
|
|
2014-04-22 06:55:11 +08:00
|
|
|
#define DEBUG_TYPE "ir"
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// UnaryConstantExpr - This class is private to Constants.cpp, and is used
|
|
|
|
/// behind the scenes to implement unary constant exprs.
|
2013-09-12 02:05:11 +08:00
|
|
|
class UnaryConstantExpr : public ConstantExpr {
|
2009-08-05 06:55:26 +08:00
|
|
|
public:
|
2011-07-18 12:54:35 +08:00
|
|
|
UnaryConstantExpr(unsigned Opcode, Constant *C, Type *Ty)
|
2009-08-05 06:55:26 +08:00
|
|
|
: ConstantExpr(Ty, Opcode, &Op<0>(), 1) {
|
|
|
|
Op<0>() = C;
|
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
|
|
|
// allocate space for exactly one operand
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 1);
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// BinaryConstantExpr - This class is private to Constants.cpp, and is used
|
|
|
|
/// behind the scenes to implement binary constant exprs.
|
2013-09-12 02:05:11 +08:00
|
|
|
class BinaryConstantExpr : public ConstantExpr {
|
2009-08-05 06:55:26 +08:00
|
|
|
public:
|
2009-09-08 07:54:19 +08:00
|
|
|
BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2,
|
|
|
|
unsigned Flags)
|
2009-08-05 06:55:26 +08:00
|
|
|
: ConstantExpr(C1->getType(), Opcode, &Op<0>(), 2) {
|
|
|
|
Op<0>() = C1;
|
|
|
|
Op<1>() = C2;
|
2009-09-08 07:54:19 +08:00
|
|
|
SubclassOptionalData = Flags;
|
2009-08-05 06:55:26 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// SelectConstantExpr - This class is private to Constants.cpp, and is used
|
|
|
|
/// behind the scenes to implement select constant exprs.
|
2013-09-12 02:05:11 +08:00
|
|
|
class SelectConstantExpr : public ConstantExpr {
|
2009-08-05 06:55:26 +08:00
|
|
|
public:
|
|
|
|
SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3)
|
|
|
|
: ConstantExpr(C2->getType(), Instruction::Select, &Op<0>(), 3) {
|
|
|
|
Op<0>() = C1;
|
|
|
|
Op<1>() = C2;
|
|
|
|
Op<2>() = C3;
|
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
|
|
|
// allocate space for exactly three operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 3);
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// ExtractElementConstantExpr - This class is private to
|
|
|
|
/// Constants.cpp, and is used behind the scenes to implement
|
|
|
|
/// extractelement constant exprs.
|
2013-09-12 02:05:11 +08:00
|
|
|
class ExtractElementConstantExpr : public ConstantExpr {
|
2009-08-05 06:55:26 +08:00
|
|
|
public:
|
|
|
|
ExtractElementConstantExpr(Constant *C1, Constant *C2)
|
2015-05-19 05:49:02 +08:00
|
|
|
: ConstantExpr(cast<VectorType>(C1->getType())->getElementType(),
|
2009-08-05 06:55:26 +08:00
|
|
|
Instruction::ExtractElement, &Op<0>(), 2) {
|
|
|
|
Op<0>() = C1;
|
|
|
|
Op<1>() = C2;
|
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// InsertElementConstantExpr - This class is private to
|
|
|
|
/// Constants.cpp, and is used behind the scenes to implement
|
|
|
|
/// insertelement constant exprs.
|
2013-09-12 02:05:11 +08:00
|
|
|
class InsertElementConstantExpr : public ConstantExpr {
|
2009-08-05 06:55:26 +08:00
|
|
|
public:
|
|
|
|
InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)
|
2015-05-19 05:49:02 +08:00
|
|
|
: ConstantExpr(C1->getType(), Instruction::InsertElement,
|
2009-08-05 06:55:26 +08:00
|
|
|
&Op<0>(), 3) {
|
|
|
|
Op<0>() = C1;
|
|
|
|
Op<1>() = C2;
|
|
|
|
Op<2>() = C3;
|
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
|
|
|
// allocate space for exactly three operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 3);
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// ShuffleVectorConstantExpr - This class is private to
|
|
|
|
/// Constants.cpp, and is used behind the scenes to implement
|
|
|
|
/// shufflevector constant exprs.
|
2013-09-12 02:05:11 +08:00
|
|
|
class ShuffleVectorConstantExpr : public ConstantExpr {
|
2009-08-05 06:55:26 +08:00
|
|
|
public:
|
|
|
|
ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3)
|
|
|
|
: ConstantExpr(VectorType::get(
|
|
|
|
cast<VectorType>(C1->getType())->getElementType(),
|
|
|
|
cast<VectorType>(C3->getType())->getNumElements()),
|
2015-05-19 05:49:02 +08:00
|
|
|
Instruction::ShuffleVector,
|
2009-08-05 06:55:26 +08:00
|
|
|
&Op<0>(), 3) {
|
|
|
|
Op<0>() = C1;
|
|
|
|
Op<1>() = C2;
|
|
|
|
Op<2>() = C3;
|
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
|
|
|
// allocate space for exactly three operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 3);
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// ExtractValueConstantExpr - This class is private to
|
|
|
|
/// Constants.cpp, and is used behind the scenes to implement
|
|
|
|
/// extractvalue constant exprs.
|
2013-09-12 02:05:11 +08:00
|
|
|
class ExtractValueConstantExpr : public ConstantExpr {
|
2009-08-05 06:55:26 +08:00
|
|
|
public:
|
2014-08-19 08:23:17 +08:00
|
|
|
ExtractValueConstantExpr(Constant *Agg, ArrayRef<unsigned> IdxList,
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *DestTy)
|
2014-08-19 08:23:17 +08:00
|
|
|
: ConstantExpr(DestTy, Instruction::ExtractValue, &Op<0>(), 1),
|
|
|
|
Indices(IdxList.begin(), IdxList.end()) {
|
2009-08-05 06:55:26 +08:00
|
|
|
Op<0>() = Agg;
|
|
|
|
}
|
|
|
|
|
2016-12-08 06:06:02 +08:00
|
|
|
// allocate space for exactly one operand
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 1);
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
/// Indices - These identify which value to extract.
|
|
|
|
const SmallVector<unsigned, 4> Indices;
|
|
|
|
|
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2015-12-15 14:11:36 +08:00
|
|
|
|
|
|
|
static bool classof(const ConstantExpr *CE) {
|
|
|
|
return CE->getOpcode() == Instruction::ExtractValue;
|
|
|
|
}
|
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
|
|
|
|
}
|
2009-08-05 06:55:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// InsertValueConstantExpr - This class is private to
|
|
|
|
/// Constants.cpp, and is used behind the scenes to implement
|
|
|
|
/// insertvalue constant exprs.
|
2013-09-12 02:05:11 +08:00
|
|
|
class InsertValueConstantExpr : public ConstantExpr {
|
2009-08-05 06:55:26 +08:00
|
|
|
public:
|
|
|
|
InsertValueConstantExpr(Constant *Agg, Constant *Val,
|
2014-08-19 08:23:17 +08:00
|
|
|
ArrayRef<unsigned> IdxList, Type *DestTy)
|
|
|
|
: ConstantExpr(DestTy, Instruction::InsertValue, &Op<0>(), 2),
|
|
|
|
Indices(IdxList.begin(), IdxList.end()) {
|
2009-08-05 06:55:26 +08:00
|
|
|
Op<0>() = Agg;
|
|
|
|
Op<1>() = Val;
|
|
|
|
}
|
|
|
|
|
2016-12-08 06:06:02 +08:00
|
|
|
// allocate space for exactly one operand
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
/// Indices - These identify the position for the insertion.
|
|
|
|
const SmallVector<unsigned, 4> Indices;
|
|
|
|
|
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2015-12-15 14:11:36 +08:00
|
|
|
|
|
|
|
static bool classof(const ConstantExpr *CE) {
|
|
|
|
return CE->getOpcode() == Instruction::InsertValue;
|
|
|
|
}
|
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
|
|
|
|
}
|
2009-08-05 06:55:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is
|
|
|
|
/// used behind the scenes to implement getelementpr constant exprs.
|
2013-09-12 02:05:11 +08:00
|
|
|
class GetElementPtrConstantExpr : public ConstantExpr {
|
2015-05-08 08:42:26 +08:00
|
|
|
Type *SrcElementTy;
|
2016-01-20 01:28:00 +08:00
|
|
|
Type *ResElementTy;
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2015-05-08 08:42:26 +08:00
|
|
|
GetElementPtrConstantExpr(Type *SrcElementTy, Constant *C,
|
|
|
|
ArrayRef<Constant *> IdxList, Type *DestTy);
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
public:
|
2015-05-08 08:42:26 +08:00
|
|
|
static GetElementPtrConstantExpr *Create(Type *SrcElementTy, Constant *C,
|
|
|
|
ArrayRef<Constant *> IdxList,
|
|
|
|
Type *DestTy, unsigned Flags) {
|
|
|
|
GetElementPtrConstantExpr *Result = new (IdxList.size() + 1)
|
|
|
|
GetElementPtrConstantExpr(SrcElementTy, C, IdxList, DestTy);
|
2009-09-08 07:54:19 +08:00
|
|
|
Result->SubclassOptionalData = Flags;
|
|
|
|
return Result;
|
2009-08-05 06:55:26 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2015-05-08 08:42:26 +08:00
|
|
|
Type *getSourceElementType() const;
|
2016-01-20 01:28:00 +08:00
|
|
|
Type *getResultElementType() const;
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2015-12-15 14:11:36 +08:00
|
|
|
|
|
|
|
static bool classof(const ConstantExpr *CE) {
|
|
|
|
return CE->getOpcode() == Instruction::GetElementPtr;
|
|
|
|
}
|
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
|
|
|
|
}
|
2009-08-05 06:55:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// CompareConstantExpr - This class is private to Constants.cpp, and is used
|
|
|
|
// behind the scenes to implement ICmp and FCmp constant expressions. This is
|
|
|
|
// needed in order to store the predicate value for these instructions.
|
2013-09-12 02:05:11 +08:00
|
|
|
class CompareConstantExpr : public ConstantExpr {
|
2011-12-20 10:50:00 +08:00
|
|
|
public:
|
2009-08-05 06:55:26 +08:00
|
|
|
unsigned short predicate;
|
2011-07-18 12:54:35 +08:00
|
|
|
CompareConstantExpr(Type *ty, Instruction::OtherOps opc,
|
2009-08-05 06:55:26 +08:00
|
|
|
unsigned short pred, Constant* LHS, Constant* RHS)
|
|
|
|
: ConstantExpr(ty, opc, &Op<0>(), 2), predicate(pred) {
|
|
|
|
Op<0>() = LHS;
|
|
|
|
Op<1>() = RHS;
|
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2015-12-15 14:11:36 +08:00
|
|
|
|
|
|
|
static bool classof(const ConstantExpr *CE) {
|
|
|
|
return CE->getOpcode() == Instruction::ICmp ||
|
|
|
|
CE->getOpcode() == Instruction::FCmp;
|
|
|
|
}
|
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
|
|
|
|
}
|
2009-08-05 06:55:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2015-05-19 05:49:02 +08:00
|
|
|
struct OperandTraits<UnaryConstantExpr>
|
|
|
|
: public FixedNumOperandTraits<UnaryConstantExpr, 1> {};
|
2009-08-05 06:55:26 +08:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryConstantExpr, Value)
|
|
|
|
|
|
|
|
template <>
|
2015-05-19 05:49:02 +08:00
|
|
|
struct OperandTraits<BinaryConstantExpr>
|
|
|
|
: public FixedNumOperandTraits<BinaryConstantExpr, 2> {};
|
2009-08-05 06:55:26 +08:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryConstantExpr, Value)
|
|
|
|
|
|
|
|
template <>
|
2015-05-19 05:49:02 +08:00
|
|
|
struct OperandTraits<SelectConstantExpr>
|
|
|
|
: public FixedNumOperandTraits<SelectConstantExpr, 3> {};
|
2009-08-05 06:55:26 +08:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectConstantExpr, Value)
|
|
|
|
|
|
|
|
template <>
|
2015-05-19 05:49:02 +08:00
|
|
|
struct OperandTraits<ExtractElementConstantExpr>
|
|
|
|
: public FixedNumOperandTraits<ExtractElementConstantExpr, 2> {};
|
2009-08-05 06:55:26 +08:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementConstantExpr, Value)
|
|
|
|
|
|
|
|
template <>
|
2015-05-19 05:49:02 +08:00
|
|
|
struct OperandTraits<InsertElementConstantExpr>
|
|
|
|
: public FixedNumOperandTraits<InsertElementConstantExpr, 3> {};
|
2009-08-05 06:55:26 +08:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementConstantExpr, Value)
|
|
|
|
|
|
|
|
template <>
|
2015-05-19 05:49:02 +08:00
|
|
|
struct OperandTraits<ShuffleVectorConstantExpr>
|
|
|
|
: public FixedNumOperandTraits<ShuffleVectorConstantExpr, 3> {};
|
2009-08-05 06:55:26 +08:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorConstantExpr, Value)
|
|
|
|
|
|
|
|
template <>
|
2015-05-19 05:49:02 +08:00
|
|
|
struct OperandTraits<ExtractValueConstantExpr>
|
|
|
|
: public FixedNumOperandTraits<ExtractValueConstantExpr, 1> {};
|
2009-08-05 06:55:26 +08:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractValueConstantExpr, Value)
|
|
|
|
|
|
|
|
template <>
|
2015-05-19 05:49:02 +08:00
|
|
|
struct OperandTraits<InsertValueConstantExpr>
|
|
|
|
: public FixedNumOperandTraits<InsertValueConstantExpr, 2> {};
|
2009-08-05 06:55:26 +08:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueConstantExpr, Value)
|
|
|
|
|
|
|
|
template <>
|
2015-05-19 05:49:02 +08:00
|
|
|
struct OperandTraits<GetElementPtrConstantExpr>
|
|
|
|
: public VariadicOperandTraits<GetElementPtrConstantExpr, 1> {};
|
2009-08-05 06:55:26 +08:00
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrConstantExpr, Value)
|
|
|
|
|
|
|
|
template <>
|
2015-05-19 05:49:02 +08:00
|
|
|
struct OperandTraits<CompareConstantExpr>
|
|
|
|
: public FixedNumOperandTraits<CompareConstantExpr, 2> {};
|
2009-08-05 06:55:26 +08:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CompareConstantExpr, Value)
|
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
template <class ConstantClass> struct ConstantAggrKeyType;
|
|
|
|
struct InlineAsmKeyType;
|
|
|
|
struct ConstantExprKeyType;
|
2014-08-19 08:42:32 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
template <class ConstantClass> struct ConstantInfo;
|
|
|
|
template <> struct ConstantInfo<ConstantExpr> {
|
2017-05-16 05:57:41 +08:00
|
|
|
using ValType = ConstantExprKeyType;
|
|
|
|
using TypeClass = Type;
|
2014-08-19 08:42:32 +08:00
|
|
|
};
|
2014-08-20 00:39:58 +08:00
|
|
|
template <> struct ConstantInfo<InlineAsm> {
|
2017-05-16 05:57:41 +08:00
|
|
|
using ValType = InlineAsmKeyType;
|
|
|
|
using TypeClass = PointerType;
|
2009-08-05 06:55:26 +08:00
|
|
|
};
|
2014-08-20 00:39:58 +08:00
|
|
|
template <> struct ConstantInfo<ConstantArray> {
|
2017-05-16 05:57:41 +08:00
|
|
|
using ValType = ConstantAggrKeyType<ConstantArray>;
|
|
|
|
using TypeClass = ArrayType;
|
2014-08-19 09:02:18 +08:00
|
|
|
};
|
2014-08-20 00:39:58 +08:00
|
|
|
template <> struct ConstantInfo<ConstantStruct> {
|
2017-05-16 05:57:41 +08:00
|
|
|
using ValType = ConstantAggrKeyType<ConstantStruct>;
|
|
|
|
using TypeClass = StructType;
|
2014-08-19 09:02:18 +08:00
|
|
|
};
|
2014-08-20 00:39:58 +08:00
|
|
|
template <> struct ConstantInfo<ConstantVector> {
|
2017-05-16 05:57:41 +08:00
|
|
|
using ValType = ConstantAggrKeyType<ConstantVector>;
|
|
|
|
using TypeClass = VectorType;
|
2014-08-19 09:02:18 +08:00
|
|
|
};
|
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
template <class ConstantClass> struct ConstantAggrKeyType {
|
|
|
|
ArrayRef<Constant *> Operands;
|
2017-05-16 05:57:41 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
ConstantAggrKeyType(ArrayRef<Constant *> Operands) : Operands(Operands) {}
|
2017-05-16 05:57:41 +08:00
|
|
|
|
2014-08-20 03:13:30 +08:00
|
|
|
ConstantAggrKeyType(ArrayRef<Constant *> Operands, const ConstantClass *)
|
|
|
|
: Operands(Operands) {}
|
2017-05-16 05:57:41 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
ConstantAggrKeyType(const ConstantClass *C,
|
|
|
|
SmallVectorImpl<Constant *> &Storage) {
|
|
|
|
assert(Storage.empty() && "Expected empty storage");
|
|
|
|
for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
|
|
|
|
Storage.push_back(C->getOperand(I));
|
|
|
|
Operands = Storage;
|
2014-08-19 09:02:18 +08:00
|
|
|
}
|
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
bool operator==(const ConstantAggrKeyType &X) const {
|
|
|
|
return Operands == X.Operands;
|
2014-08-19 09:02:18 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
bool operator==(const ConstantClass *C) const {
|
|
|
|
if (Operands.size() != C->getNumOperands())
|
|
|
|
return false;
|
|
|
|
for (unsigned I = 0, E = Operands.size(); I != E; ++I)
|
|
|
|
if (Operands[I] != C->getOperand(I))
|
|
|
|
return false;
|
|
|
|
return true;
|
2014-08-19 09:02:18 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
unsigned getHash() const {
|
|
|
|
return hash_combine_range(Operands.begin(), Operands.end());
|
2014-08-19 09:02:18 +08:00
|
|
|
}
|
|
|
|
|
2017-05-16 05:57:41 +08:00
|
|
|
using TypeClass = typename ConstantInfo<ConstantClass>::TypeClass;
|
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
ConstantClass *create(TypeClass *Ty) const {
|
|
|
|
return new (Operands.size()) ConstantClass(Ty, Operands);
|
2014-08-19 09:02:18 +08:00
|
|
|
}
|
|
|
|
};
|
2009-08-05 06:55:26 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
struct InlineAsmKeyType {
|
|
|
|
StringRef AsmString;
|
|
|
|
StringRef Constraints;
|
2015-07-28 08:06:38 +08:00
|
|
|
FunctionType *FTy;
|
2014-08-20 00:39:58 +08:00
|
|
|
bool HasSideEffects;
|
|
|
|
bool IsAlignStack;
|
|
|
|
InlineAsm::AsmDialect AsmDialect;
|
|
|
|
|
|
|
|
InlineAsmKeyType(StringRef AsmString, StringRef Constraints,
|
2015-07-28 08:06:38 +08:00
|
|
|
FunctionType *FTy, bool HasSideEffects, bool IsAlignStack,
|
2014-08-20 00:39:58 +08:00
|
|
|
InlineAsm::AsmDialect AsmDialect)
|
2015-07-28 08:06:38 +08:00
|
|
|
: AsmString(AsmString), Constraints(Constraints), FTy(FTy),
|
2014-08-20 00:39:58 +08:00
|
|
|
HasSideEffects(HasSideEffects), IsAlignStack(IsAlignStack),
|
|
|
|
AsmDialect(AsmDialect) {}
|
2017-05-16 05:57:41 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
InlineAsmKeyType(const InlineAsm *Asm, SmallVectorImpl<Constant *> &)
|
|
|
|
: AsmString(Asm->getAsmString()), Constraints(Asm->getConstraintString()),
|
2015-07-28 08:06:38 +08:00
|
|
|
FTy(Asm->getFunctionType()), HasSideEffects(Asm->hasSideEffects()),
|
2014-08-20 00:39:58 +08:00
|
|
|
IsAlignStack(Asm->isAlignStack()), AsmDialect(Asm->getDialect()) {}
|
|
|
|
|
|
|
|
bool operator==(const InlineAsmKeyType &X) const {
|
|
|
|
return HasSideEffects == X.HasSideEffects &&
|
|
|
|
IsAlignStack == X.IsAlignStack && AsmDialect == X.AsmDialect &&
|
2015-07-28 08:06:38 +08:00
|
|
|
AsmString == X.AsmString && Constraints == X.Constraints &&
|
|
|
|
FTy == X.FTy;
|
2014-08-20 00:39:58 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
bool operator==(const InlineAsm *Asm) const {
|
|
|
|
return HasSideEffects == Asm->hasSideEffects() &&
|
|
|
|
IsAlignStack == Asm->isAlignStack() &&
|
|
|
|
AsmDialect == Asm->getDialect() &&
|
|
|
|
AsmString == Asm->getAsmString() &&
|
2015-07-28 08:06:38 +08:00
|
|
|
Constraints == Asm->getConstraintString() &&
|
|
|
|
FTy == Asm->getFunctionType();
|
2014-08-20 00:39:58 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
unsigned getHash() const {
|
|
|
|
return hash_combine(AsmString, Constraints, HasSideEffects, IsAlignStack,
|
2015-07-28 08:06:38 +08:00
|
|
|
AsmDialect, FTy);
|
2014-08-20 00:39:58 +08:00
|
|
|
}
|
|
|
|
|
2017-05-16 05:57:41 +08:00
|
|
|
using TypeClass = ConstantInfo<InlineAsm>::TypeClass;
|
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
InlineAsm *create(TypeClass *Ty) const {
|
2015-07-28 08:06:38 +08:00
|
|
|
assert(PointerType::getUnqual(FTy) == Ty);
|
|
|
|
return new InlineAsm(FTy, AsmString, Constraints, HasSideEffects,
|
2014-08-20 00:39:58 +08:00
|
|
|
IsAlignStack, AsmDialect);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConstantExprKeyType {
|
|
|
|
uint8_t Opcode;
|
|
|
|
uint8_t SubclassOptionalData;
|
|
|
|
uint16_t SubclassData;
|
|
|
|
ArrayRef<Constant *> Ops;
|
|
|
|
ArrayRef<unsigned> Indexes;
|
2015-05-08 08:42:26 +08:00
|
|
|
Type *ExplicitTy;
|
2014-08-20 00:39:58 +08:00
|
|
|
|
|
|
|
ConstantExprKeyType(unsigned Opcode, ArrayRef<Constant *> Ops,
|
|
|
|
unsigned short SubclassData = 0,
|
|
|
|
unsigned short SubclassOptionalData = 0,
|
2015-05-08 08:42:26 +08:00
|
|
|
ArrayRef<unsigned> Indexes = None,
|
|
|
|
Type *ExplicitTy = nullptr)
|
2014-08-20 00:39:58 +08:00
|
|
|
: Opcode(Opcode), SubclassOptionalData(SubclassOptionalData),
|
2015-05-08 08:42:26 +08:00
|
|
|
SubclassData(SubclassData), Ops(Ops), Indexes(Indexes),
|
|
|
|
ExplicitTy(ExplicitTy) {}
|
2017-05-16 05:57:41 +08:00
|
|
|
|
2014-08-20 03:13:30 +08:00
|
|
|
ConstantExprKeyType(ArrayRef<Constant *> Operands, const ConstantExpr *CE)
|
|
|
|
: Opcode(CE->getOpcode()),
|
|
|
|
SubclassOptionalData(CE->getRawSubclassOptionalData()),
|
|
|
|
SubclassData(CE->isCompare() ? CE->getPredicate() : 0), Ops(Operands),
|
|
|
|
Indexes(CE->hasIndices() ? CE->getIndices() : ArrayRef<unsigned>()) {}
|
2017-05-16 05:57:41 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
ConstantExprKeyType(const ConstantExpr *CE,
|
|
|
|
SmallVectorImpl<Constant *> &Storage)
|
|
|
|
: Opcode(CE->getOpcode()),
|
|
|
|
SubclassOptionalData(CE->getRawSubclassOptionalData()),
|
|
|
|
SubclassData(CE->isCompare() ? CE->getPredicate() : 0),
|
|
|
|
Indexes(CE->hasIndices() ? CE->getIndices() : ArrayRef<unsigned>()) {
|
|
|
|
assert(Storage.empty() && "Expected empty storage");
|
|
|
|
for (unsigned I = 0, E = CE->getNumOperands(); I != E; ++I)
|
|
|
|
Storage.push_back(CE->getOperand(I));
|
|
|
|
Ops = Storage;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const ConstantExprKeyType &X) const {
|
|
|
|
return Opcode == X.Opcode && SubclassData == X.SubclassData &&
|
|
|
|
SubclassOptionalData == X.SubclassOptionalData && Ops == X.Ops &&
|
|
|
|
Indexes == X.Indexes;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const ConstantExpr *CE) const {
|
|
|
|
if (Opcode != CE->getOpcode())
|
|
|
|
return false;
|
|
|
|
if (SubclassOptionalData != CE->getRawSubclassOptionalData())
|
|
|
|
return false;
|
|
|
|
if (Ops.size() != CE->getNumOperands())
|
|
|
|
return false;
|
|
|
|
if (SubclassData != (CE->isCompare() ? CE->getPredicate() : 0))
|
|
|
|
return false;
|
|
|
|
for (unsigned I = 0, E = Ops.size(); I != E; ++I)
|
|
|
|
if (Ops[I] != CE->getOperand(I))
|
|
|
|
return false;
|
|
|
|
if (Indexes != (CE->hasIndices() ? CE->getIndices() : ArrayRef<unsigned>()))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getHash() const {
|
|
|
|
return hash_combine(Opcode, SubclassOptionalData, SubclassData,
|
|
|
|
hash_combine_range(Ops.begin(), Ops.end()),
|
|
|
|
hash_combine_range(Indexes.begin(), Indexes.end()));
|
|
|
|
}
|
|
|
|
|
2017-05-16 05:57:41 +08:00
|
|
|
using TypeClass = ConstantInfo<ConstantExpr>::TypeClass;
|
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
ConstantExpr *create(TypeClass *Ty) const {
|
|
|
|
switch (Opcode) {
|
|
|
|
default:
|
|
|
|
if (Instruction::isCast(Opcode))
|
|
|
|
return new UnaryConstantExpr(Opcode, Ops[0], Ty);
|
|
|
|
if ((Opcode >= Instruction::BinaryOpsBegin &&
|
|
|
|
Opcode < Instruction::BinaryOpsEnd))
|
|
|
|
return new BinaryConstantExpr(Opcode, Ops[0], Ops[1],
|
|
|
|
SubclassOptionalData);
|
|
|
|
llvm_unreachable("Invalid ConstantExpr!");
|
|
|
|
case Instruction::Select:
|
|
|
|
return new SelectConstantExpr(Ops[0], Ops[1], Ops[2]);
|
|
|
|
case Instruction::ExtractElement:
|
|
|
|
return new ExtractElementConstantExpr(Ops[0], Ops[1]);
|
|
|
|
case Instruction::InsertElement:
|
|
|
|
return new InsertElementConstantExpr(Ops[0], Ops[1], Ops[2]);
|
|
|
|
case Instruction::ShuffleVector:
|
|
|
|
return new ShuffleVectorConstantExpr(Ops[0], Ops[1], Ops[2]);
|
|
|
|
case Instruction::InsertValue:
|
|
|
|
return new InsertValueConstantExpr(Ops[0], Ops[1], Indexes, Ty);
|
|
|
|
case Instruction::ExtractValue:
|
|
|
|
return new ExtractValueConstantExpr(Ops[0], Indexes, Ty);
|
|
|
|
case Instruction::GetElementPtr:
|
2015-05-08 08:42:26 +08:00
|
|
|
return GetElementPtrConstantExpr::Create(
|
|
|
|
ExplicitTy ? ExplicitTy
|
|
|
|
: cast<PointerType>(Ops[0]->getType()->getScalarType())
|
|
|
|
->getElementType(),
|
|
|
|
Ops[0], Ops.slice(1), Ty, SubclassOptionalData);
|
2014-08-20 00:39:58 +08:00
|
|
|
case Instruction::ICmp:
|
|
|
|
return new CompareConstantExpr(Ty, Instruction::ICmp, SubclassData,
|
|
|
|
Ops[0], Ops[1]);
|
|
|
|
case Instruction::FCmp:
|
|
|
|
return new CompareConstantExpr(Ty, Instruction::FCmp, SubclassData,
|
|
|
|
Ops[0], Ops[1]);
|
2014-08-19 22:59:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
template <class ConstantClass> class ConstantUniqueMap {
|
2014-08-19 22:59:02 +08:00
|
|
|
public:
|
2017-05-16 05:57:41 +08:00
|
|
|
using ValType = typename ConstantInfo<ConstantClass>::ValType;
|
|
|
|
using TypeClass = typename ConstantInfo<ConstantClass>::TypeClass;
|
|
|
|
using LookupKey = std::pair<TypeClass *, ValType>;
|
2014-08-20 00:39:58 +08:00
|
|
|
|
2016-03-07 08:51:00 +08:00
|
|
|
/// Key and hash together, so that we compute the hash only once and reuse it.
|
2017-05-16 05:57:41 +08:00
|
|
|
using LookupKeyHashed = std::pair<unsigned, LookupKey>;
|
2016-03-07 08:51:00 +08:00
|
|
|
|
2014-08-19 08:42:32 +08:00
|
|
|
private:
|
|
|
|
struct MapInfo {
|
2017-05-16 05:57:41 +08:00
|
|
|
using ConstantClassInfo = DenseMapInfo<ConstantClass *>;
|
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
static inline ConstantClass *getEmptyKey() {
|
2014-08-19 08:42:32 +08:00
|
|
|
return ConstantClassInfo::getEmptyKey();
|
2009-08-05 06:55:26 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
static inline ConstantClass *getTombstoneKey() {
|
2014-08-19 08:42:32 +08:00
|
|
|
return ConstantClassInfo::getTombstoneKey();
|
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2014-08-19 08:42:32 +08:00
|
|
|
static unsigned getHashValue(const ConstantClass *CP) {
|
2016-04-19 08:17:55 +08:00
|
|
|
SmallVector<Constant *, 32> Storage;
|
2014-08-20 00:39:58 +08:00
|
|
|
return getHashValue(LookupKey(CP->getType(), ValType(CP, Storage)));
|
2014-08-19 08:42:32 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2014-08-19 08:42:32 +08:00
|
|
|
static bool isEqual(const ConstantClass *LHS, const ConstantClass *RHS) {
|
|
|
|
return LHS == RHS;
|
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2014-08-19 08:42:32 +08:00
|
|
|
static unsigned getHashValue(const LookupKey &Val) {
|
2014-08-20 00:39:58 +08:00
|
|
|
return hash_combine(Val.first, Val.second.getHash());
|
2014-08-19 08:42:32 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2016-03-07 08:51:00 +08:00
|
|
|
static unsigned getHashValue(const LookupKeyHashed &Val) {
|
|
|
|
return Val.first;
|
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2014-08-19 08:42:32 +08:00
|
|
|
static bool isEqual(const LookupKey &LHS, const ConstantClass *RHS) {
|
|
|
|
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
|
|
|
|
return false;
|
2014-08-20 00:39:58 +08:00
|
|
|
if (LHS.first != RHS->getType())
|
2014-08-19 08:42:32 +08:00
|
|
|
return false;
|
2014-08-20 00:39:58 +08:00
|
|
|
return LHS.second == RHS;
|
2014-08-19 08:42:32 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2016-03-07 08:51:00 +08:00
|
|
|
static bool isEqual(const LookupKeyHashed &LHS, const ConstantClass *RHS) {
|
|
|
|
return isEqual(LHS.second, RHS);
|
|
|
|
}
|
2014-08-19 08:42:32 +08:00
|
|
|
};
|
2014-08-20 00:39:58 +08:00
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
public:
|
2017-05-16 05:57:41 +08:00
|
|
|
using MapTy = DenseSet<ConstantClass *, MapInfo>;
|
2014-08-19 08:42:32 +08:00
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
private:
|
|
|
|
MapTy Map;
|
|
|
|
|
|
|
|
public:
|
2016-04-07 01:56:08 +08:00
|
|
|
typename MapTy::iterator begin() { return Map.begin(); }
|
|
|
|
typename MapTy::iterator end() { return Map.end(); }
|
2009-09-01 00:14:59 +08:00
|
|
|
|
|
|
|
void freeConstants() {
|
2014-08-20 00:39:58 +08:00
|
|
|
for (auto &I : Map)
|
2016-04-07 01:56:08 +08:00
|
|
|
delete I; // Asserts that use_empty().
|
2009-08-05 06:55:26 +08:00
|
|
|
}
|
2016-12-08 06:06:02 +08:00
|
|
|
|
2014-08-19 08:42:32 +08:00
|
|
|
private:
|
2016-03-07 08:51:00 +08:00
|
|
|
ConstantClass *create(TypeClass *Ty, ValType V, LookupKeyHashed &HashKey) {
|
2014-08-20 00:39:58 +08:00
|
|
|
ConstantClass *Result = V.create(Ty);
|
2009-08-05 06:55:26 +08:00
|
|
|
|
|
|
|
assert(Result->getType() == Ty && "Type specified is not correct!");
|
2016-04-07 01:56:08 +08:00
|
|
|
Map.insert_as(Result, HashKey);
|
2009-08-05 06:55:26 +08:00
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
2014-08-19 22:59:02 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
public:
|
|
|
|
/// Return the specified constant from the map, creating it if necessary.
|
|
|
|
ConstantClass *getOrCreate(TypeClass *Ty, ValType V) {
|
2016-03-07 08:51:00 +08:00
|
|
|
LookupKey Key(Ty, V);
|
|
|
|
/// Hash once, and reuse it for the lookup and the insertion if needed.
|
|
|
|
LookupKeyHashed Lookup(MapInfo::getHashValue(Key), Key);
|
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
ConstantClass *Result = nullptr;
|
2014-08-19 08:42:32 +08:00
|
|
|
|
2016-03-07 08:51:00 +08:00
|
|
|
auto I = Map.find_as(Lookup);
|
2014-08-20 00:39:58 +08:00
|
|
|
if (I == Map.end())
|
2016-03-07 08:51:00 +08:00
|
|
|
Result = create(Ty, V, Lookup);
|
2014-08-20 00:39:58 +08:00
|
|
|
else
|
2016-04-07 01:56:08 +08:00
|
|
|
Result = *I;
|
2014-08-20 00:39:58 +08:00
|
|
|
assert(Result && "Unexpected nullptr");
|
2014-08-19 08:42:32 +08:00
|
|
|
|
2009-08-05 06:55:26 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2014-08-19 08:42:32 +08:00
|
|
|
/// Remove this constant from the map
|
|
|
|
void remove(ConstantClass *CP) {
|
2014-08-20 00:39:58 +08:00
|
|
|
typename MapTy::iterator I = Map.find(CP);
|
2014-08-19 08:42:32 +08:00
|
|
|
assert(I != Map.end() && "Constant not found in constant table!");
|
2016-04-07 01:56:08 +08:00
|
|
|
assert(*I == CP && "Didn't find correct element?");
|
2009-08-05 06:55:26 +08:00
|
|
|
Map.erase(I);
|
|
|
|
}
|
|
|
|
|
2014-08-20 03:13:30 +08:00
|
|
|
ConstantClass *replaceOperandsInPlace(ArrayRef<Constant *> Operands,
|
|
|
|
ConstantClass *CP, Value *From,
|
|
|
|
Constant *To, unsigned NumUpdated = 0,
|
|
|
|
unsigned OperandNo = ~0u) {
|
2016-03-07 08:51:00 +08:00
|
|
|
LookupKey Key(CP->getType(), ValType(Operands, CP));
|
|
|
|
/// Hash once, and reuse it for the lookup and the insertion if needed.
|
|
|
|
LookupKeyHashed Lookup(MapInfo::getHashValue(Key), Key);
|
|
|
|
|
|
|
|
auto I = Map.find_as(Lookup);
|
2014-08-20 03:13:30 +08:00
|
|
|
if (I != Map.end())
|
2016-04-07 01:56:08 +08:00
|
|
|
return *I;
|
2014-08-20 03:13:30 +08:00
|
|
|
|
|
|
|
// Update to the new value. Optimize for the case when we have a single
|
|
|
|
// operand that we're changing, but handle bulk updates efficiently.
|
|
|
|
remove(CP);
|
|
|
|
if (NumUpdated == 1) {
|
|
|
|
assert(OperandNo < CP->getNumOperands() && "Invalid index");
|
|
|
|
assert(CP->getOperand(OperandNo) != To && "I didn't contain From!");
|
|
|
|
CP->setOperand(OperandNo, To);
|
|
|
|
} else {
|
|
|
|
for (unsigned I = 0, E = CP->getNumOperands(); I != E; ++I)
|
|
|
|
if (CP->getOperand(I) == From)
|
|
|
|
CP->setOperand(I, To);
|
|
|
|
}
|
2016-04-07 01:56:08 +08:00
|
|
|
Map.insert_as(CP, Lookup);
|
2014-08-20 03:13:30 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
void dump() const { DEBUG(dbgs() << "Constant.cpp: ConstantUniqueMap\n"); }
|
2009-08-05 06:55:26 +08:00
|
|
|
};
|
|
|
|
|
2014-08-19 08:21:04 +08:00
|
|
|
} // end namespace llvm
|
2009-08-05 06:55:26 +08:00
|
|
|
|
2016-12-08 06:06:02 +08:00
|
|
|
#endif // LLVM_LIB_IR_CONSTANTSCONTEXT_H
|