2009-06-30 08:48:55 +08:00
|
|
|
//===-- LLVMContext.cpp - Implement LLVMContext -----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-07-01 01:06:46 +08:00
|
|
|
//
|
|
|
|
// This file implements LLVMContext, as a wrapper around the opaque
|
|
|
|
// class LLVMContextImpl.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-30 08:48:55 +08:00
|
|
|
|
|
|
|
#include "llvm/LLVMContext.h"
|
|
|
|
#include "llvm/Constants.h"
|
2009-07-01 01:50:28 +08:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2009-07-13 12:09:18 +08:00
|
|
|
#include "llvm/Instruction.h"
|
2009-07-03 01:12:48 +08:00
|
|
|
#include "llvm/MDNode.h"
|
2009-07-01 07:39:59 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2009-06-30 08:48:55 +08:00
|
|
|
#include "LLVMContextImpl.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2009-07-01 07:39:59 +08:00
|
|
|
static ManagedStatic<LLVMContext> GlobalContext;
|
|
|
|
|
2009-07-02 07:13:44 +08:00
|
|
|
LLVMContext& llvm::getGlobalContext() {
|
2009-07-02 05:22:36 +08:00
|
|
|
return *GlobalContext;
|
2009-07-01 07:39:59 +08:00
|
|
|
}
|
|
|
|
|
2009-06-30 08:48:55 +08:00
|
|
|
LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl()) { }
|
|
|
|
LLVMContext::~LLVMContext() { delete pImpl; }
|
|
|
|
|
2009-07-02 07:56:45 +08:00
|
|
|
// Constant accessors
|
2009-07-13 12:09:18 +08:00
|
|
|
|
|
|
|
// Constructor to create a '0' constant of arbitrary type...
|
|
|
|
static const uint64_t zero[2] = {0, 0};
|
2009-07-02 07:56:45 +08:00
|
|
|
Constant* LLVMContext::getNullValue(const Type* Ty) {
|
2009-07-13 12:09:18 +08:00
|
|
|
switch (Ty->getTypeID()) {
|
|
|
|
case Type::IntegerTyID:
|
|
|
|
return getConstantInt(Ty, 0);
|
|
|
|
case Type::FloatTyID:
|
|
|
|
return getConstantFP(APFloat(APInt(32, 0)));
|
|
|
|
case Type::DoubleTyID:
|
|
|
|
return getConstantFP(APFloat(APInt(64, 0)));
|
|
|
|
case Type::X86_FP80TyID:
|
|
|
|
return getConstantFP(APFloat(APInt(80, 2, zero)));
|
|
|
|
case Type::FP128TyID:
|
|
|
|
return getConstantFP(APFloat(APInt(128, 2, zero), true));
|
|
|
|
case Type::PPC_FP128TyID:
|
|
|
|
return getConstantFP(APFloat(APInt(128, 2, zero)));
|
|
|
|
case Type::PointerTyID:
|
|
|
|
return getConstantPointerNull(cast<PointerType>(Ty));
|
|
|
|
case Type::StructTyID:
|
|
|
|
case Type::ArrayTyID:
|
|
|
|
case Type::VectorTyID:
|
|
|
|
return getConstantAggregateZero(Ty);
|
|
|
|
default:
|
|
|
|
// Function, Label, or Opaque type?
|
|
|
|
assert(!"Cannot create a null constant of that type!");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-07-02 07:56:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
|
|
|
|
return Constant::getAllOnesValue(Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-03 00:51:51 +08:00
|
|
|
// UndefValue accessors.
|
|
|
|
UndefValue* LLVMContext::getUndef(const Type* Ty) {
|
|
|
|
return UndefValue::get(Ty);
|
|
|
|
}
|
|
|
|
|
2009-06-30 08:48:55 +08:00
|
|
|
// ConstantInt accessors.
|
2009-07-02 06:33:26 +08:00
|
|
|
ConstantInt* LLVMContext::getConstantIntTrue() {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantInt::getTrue();
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
ConstantInt* LLVMContext::getConstantIntFalse() {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantInt::getFalse();
|
|
|
|
}
|
|
|
|
|
2009-07-03 07:58:19 +08:00
|
|
|
Constant* LLVMContext::getConstantInt(const Type* Ty, uint64_t V,
|
|
|
|
bool isSigned) {
|
|
|
|
return ConstantInt::get(Ty, V, isSigned);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-30 08:48:55 +08:00
|
|
|
ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V,
|
2009-07-02 06:33:26 +08:00
|
|
|
bool isSigned) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantInt::get(Ty, V, isSigned);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty,
|
2009-07-02 06:33:26 +08:00
|
|
|
int64_t V) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantInt::getSigned(Ty, V);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantInt::get(V);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantInt::get(Ty, V);
|
|
|
|
}
|
|
|
|
|
2009-07-03 07:58:19 +08:00
|
|
|
ConstantInt* LLVMContext::getConstantIntAllOnesValue(const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantInt::getAllOnesValue(Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ConstantPointerNull accessors.
|
2009-07-02 06:33:26 +08:00
|
|
|
ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantPointerNull::get(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ConstantStruct accessors.
|
|
|
|
Constant* LLVMContext::getConstantStruct(const StructType* T,
|
2009-07-02 06:33:26 +08:00
|
|
|
const std::vector<Constant*>& V) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantStruct::get(T, V);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantStruct(const std::vector<Constant*>& V,
|
2009-07-02 06:33:26 +08:00
|
|
|
bool Packed) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantStruct::get(V, Packed);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantStruct(Constant* const *Vals,
|
2009-07-02 06:33:26 +08:00
|
|
|
unsigned NumVals, bool Packed) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantStruct::get(Vals, NumVals, Packed);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ConstantAggregateZero accessors.
|
2009-07-02 06:33:26 +08:00
|
|
|
ConstantAggregateZero* LLVMContext::getConstantAggregateZero(const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantAggregateZero::get(Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ConstantArray accessors.
|
|
|
|
Constant* LLVMContext::getConstantArray(const ArrayType* T,
|
2009-07-02 06:33:26 +08:00
|
|
|
const std::vector<Constant*>& V) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantArray::get(T, V);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantArray(const ArrayType* T,
|
|
|
|
Constant* const* Vals,
|
2009-07-02 06:33:26 +08:00
|
|
|
unsigned NumVals) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantArray::get(T, Vals, NumVals);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantArray(const std::string& Initializer,
|
2009-07-02 06:33:26 +08:00
|
|
|
bool AddNull) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantArray::get(Initializer, AddNull);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ConstantExpr accessors.
|
|
|
|
Constant* LLVMContext::getConstantExpr(unsigned Opcode, Constant* C1,
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::get(Opcode, C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprTrunc(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getTrunc(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprSExt(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getSExt(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprZExt(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getZExt(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFPTrunc(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFPTrunc(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFPExtend(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFPExtend(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprUIToFP(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getUIToFP(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprSIToFP(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getSIToFP(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFPToUI(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFPToUI(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFPToSI(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFPToSI(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprPtrToInt(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getPtrToInt(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprIntToPtr(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getIntToPtr(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprBitCast(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getBitCast(C, Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprCast(unsigned ops, Constant* C,
|
2009-07-02 06:33:26 +08:00
|
|
|
const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getCast(ops, C, Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprZExtOrBitCast(Constant* C,
|
2009-07-02 06:33:26 +08:00
|
|
|
const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getZExtOrBitCast(C, Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprSExtOrBitCast(Constant* C,
|
2009-07-02 06:33:26 +08:00
|
|
|
const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getSExtOrBitCast(C, Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprTruncOrBitCast(Constant* C,
|
2009-07-02 06:33:26 +08:00
|
|
|
const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getTruncOrBitCast(C, Ty);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprPointerCast(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getPointerCast(C, Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprIntegerCast(Constant* C, const Type* Ty,
|
2009-07-02 06:33:26 +08:00
|
|
|
bool isSigned) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getIntegerCast(C, Ty, isSigned);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFPCast(Constant* C, const Type* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFPCast(C, Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprSelect(Constant* C, Constant* V1,
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* V2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getSelect(C, V1, V2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprAlignOf(const Type* Ty) {
|
2009-07-13 12:09:18 +08:00
|
|
|
// alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1
|
|
|
|
const Type *AligningTy = getStructType(Type::Int8Ty, Ty, NULL);
|
|
|
|
Constant *NullPtr = getNullValue(AligningTy->getPointerTo());
|
|
|
|
Constant *Zero = getConstantInt(Type::Int32Ty, 0);
|
|
|
|
Constant *One = getConstantInt(Type::Int32Ty, 1);
|
|
|
|
Constant *Indices[2] = { Zero, One };
|
|
|
|
Constant *GEP = getConstantExprGetElementPtr(NullPtr, Indices, 2);
|
|
|
|
return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int32Ty);
|
2009-06-30 08:48:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprCompare(unsigned short pred,
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getCompare(pred, C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprNeg(Constant* C) {
|
2009-07-13 12:09:18 +08:00
|
|
|
// API compatibility: Adjust integer opcodes to floating-point opcodes.
|
|
|
|
if (C->getType()->isFPOrFPVector())
|
|
|
|
return getConstantExprFNeg(C);
|
|
|
|
assert(C->getType()->isIntOrIntVector() &&
|
|
|
|
"Cannot NEG a nonintegral value!");
|
|
|
|
return getConstantExpr(Instruction::Sub,
|
|
|
|
getZeroValueForNegation(C->getType()),
|
|
|
|
C);
|
2009-06-30 08:48:55 +08:00
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFNeg(Constant* C) {
|
2009-07-13 12:09:18 +08:00
|
|
|
assert(C->getType()->isFPOrFPVector() &&
|
|
|
|
"Cannot FNEG a non-floating-point value!");
|
|
|
|
return getConstantExpr(Instruction::FSub,
|
|
|
|
getZeroValueForNegation(C->getType()),
|
|
|
|
C);
|
2009-06-30 08:48:55 +08:00
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprNot(Constant* C) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getNot(C);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprAdd(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getAdd(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFAdd(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFAdd(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprSub(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getSub(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFSub(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFSub(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprMul(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getMul(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFMul(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFMul(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprUDiv(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getUDiv(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprSDiv(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getSDiv(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFDiv(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFDiv(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprURem(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getURem(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprSRem(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getSRem(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprFRem(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFRem(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprAnd(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getAnd(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprOr(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getOr(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprXor(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getXor(C1, C2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprICmp(unsigned short pred, Constant* LHS,
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* RHS) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getICmp(pred, LHS, RHS);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprFCmp(unsigned short pred, Constant* LHS,
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* RHS) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getFCmp(pred, LHS, RHS);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprShl(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getShl(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprLShr(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getLShr(C1, C2);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantExprAShr(Constant* C1, Constant* C2) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getAShr(C1, C2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
|
|
|
|
Constant* const* IdxList,
|
2009-07-02 06:33:26 +08:00
|
|
|
unsigned NumIdx) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
|
|
|
|
Value* const* IdxList,
|
2009-07-02 06:33:26 +08:00
|
|
|
unsigned NumIdx) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprExtractElement(Constant* Vec,
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* Idx) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getExtractElement(Vec, Idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprInsertElement(Constant* Vec,
|
|
|
|
Constant* Elt,
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* Idx) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getInsertElement(Vec, Elt, Idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprShuffleVector(Constant* V1, Constant* V2,
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* Mask) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getShuffleVector(V1, V2, Mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprExtractValue(Constant* Agg,
|
|
|
|
const unsigned* IdxList,
|
2009-07-02 06:33:26 +08:00
|
|
|
unsigned NumIdx) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getExtractValue(Agg, IdxList, NumIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val,
|
|
|
|
const unsigned* IdxList,
|
2009-07-02 06:33:26 +08:00
|
|
|
unsigned NumIdx) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
|
|
|
|
}
|
|
|
|
|
2009-07-06 06:41:43 +08:00
|
|
|
Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) {
|
2009-07-13 12:09:18 +08:00
|
|
|
// sizeof is implemented as: (i64) gep (Ty*)null, 1
|
|
|
|
Constant *GEPIdx = getConstantInt(Type::Int32Ty, 1);
|
|
|
|
Constant *GEP = getConstantExprGetElementPtr(
|
|
|
|
getNullValue(getPointerTypeUnqual(Ty)), &GEPIdx, 1);
|
|
|
|
return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
|
2009-07-06 06:41:43 +08:00
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
|
2009-07-13 12:09:18 +08:00
|
|
|
if (const VectorType *PTy = dyn_cast<VectorType>(Ty))
|
|
|
|
if (PTy->getElementType()->isFloatingPoint()) {
|
|
|
|
std::vector<Constant*> zeros(PTy->getNumElements(),
|
|
|
|
getConstantFPNegativeZero(PTy->getElementType()));
|
|
|
|
return getConstantVector(PTy, zeros);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Ty->isFloatingPoint())
|
|
|
|
return getConstantFPNegativeZero(Ty);
|
|
|
|
|
|
|
|
return getNullValue(Ty);
|
2009-06-30 08:48:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ConstantFP accessors.
|
2009-07-02 06:33:26 +08:00
|
|
|
ConstantFP* LLVMContext::getConstantFP(const APFloat& V) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantFP::get(V);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantFP(const Type* Ty, double V) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantFP::get(Ty, V);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
ConstantFP* LLVMContext::getConstantFPNegativeZero(const Type* Ty) {
|
2009-07-13 12:09:18 +08:00
|
|
|
APFloat apf = cast <ConstantFP>(getNullValue(Ty))->getValueAPF();
|
|
|
|
apf.changeSign();
|
|
|
|
return getConstantFP(apf);
|
2009-06-30 08:48:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ConstantVector accessors.
|
|
|
|
Constant* LLVMContext::getConstantVector(const VectorType* T,
|
2009-07-02 06:33:26 +08:00
|
|
|
const std::vector<Constant*>& V) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantVector::get(T, V);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& V) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantVector::get(V);
|
|
|
|
}
|
|
|
|
|
|
|
|
Constant* LLVMContext::getConstantVector(Constant* const* Vals,
|
2009-07-02 06:33:26 +08:00
|
|
|
unsigned NumVals) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantVector::get(Vals, NumVals);
|
|
|
|
}
|
|
|
|
|
2009-07-04 03:42:02 +08:00
|
|
|
ConstantVector* LLVMContext::getConstantVectorAllOnesValue(
|
|
|
|
const VectorType* Ty) {
|
2009-06-30 08:48:55 +08:00
|
|
|
return ConstantVector::getAllOnesValue(Ty);
|
|
|
|
}
|
2009-07-01 01:50:28 +08:00
|
|
|
|
2009-07-03 01:12:48 +08:00
|
|
|
// MDNode accessors
|
|
|
|
MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
|
|
|
|
return MDNode::get(Vals, NumVals);
|
|
|
|
}
|
|
|
|
|
2009-07-03 01:19:47 +08:00
|
|
|
// MDString accessors
|
|
|
|
MDString* LLVMContext::getMDString(const char *StrBegin, const char *StrEnd) {
|
|
|
|
return MDString::get(StrBegin, StrEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
MDString* LLVMContext::getMDString(const std::string &Str) {
|
|
|
|
return MDString::get(Str);
|
|
|
|
}
|
|
|
|
|
2009-07-01 01:50:28 +08:00
|
|
|
// FunctionType accessors
|
2009-07-06 06:41:43 +08:00
|
|
|
FunctionType* LLVMContext::getFunctionType(const Type* Result, bool isVarArg) {
|
|
|
|
return FunctionType::get(Result, isVarArg);
|
|
|
|
}
|
|
|
|
|
2009-07-01 01:50:28 +08:00
|
|
|
FunctionType* LLVMContext::getFunctionType(const Type* Result,
|
|
|
|
const std::vector<const Type*>& Params,
|
2009-07-02 06:33:26 +08:00
|
|
|
bool isVarArg) {
|
2009-07-01 01:50:28 +08:00
|
|
|
return FunctionType::get(Result, Params, isVarArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// IntegerType accessors
|
2009-07-02 06:33:26 +08:00
|
|
|
const IntegerType* LLVMContext::getIntegerType(unsigned NumBits) {
|
2009-07-01 01:50:28 +08:00
|
|
|
return IntegerType::get(NumBits);
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpaqueType accessors
|
2009-07-02 06:33:26 +08:00
|
|
|
OpaqueType* LLVMContext::getOpaqueType() {
|
2009-07-01 01:50:28 +08:00
|
|
|
return OpaqueType::get();
|
|
|
|
}
|
|
|
|
|
|
|
|
// StructType accessors
|
2009-07-02 07:56:45 +08:00
|
|
|
StructType* LLVMContext::getStructType(bool isPacked) {
|
|
|
|
return StructType::get(isPacked);
|
|
|
|
}
|
|
|
|
|
2009-07-01 01:50:28 +08:00
|
|
|
StructType* LLVMContext::getStructType(const std::vector<const Type*>& Params,
|
2009-07-02 06:33:26 +08:00
|
|
|
bool isPacked) {
|
2009-07-01 01:50:28 +08:00
|
|
|
return StructType::get(Params, isPacked);
|
|
|
|
}
|
|
|
|
|
2009-07-13 12:09:18 +08:00
|
|
|
StructType *LLVMContext::getStructType(const Type *type, ...) {
|
|
|
|
va_list ap;
|
|
|
|
std::vector<const llvm::Type*> StructFields;
|
|
|
|
va_start(ap, type);
|
|
|
|
while (type) {
|
|
|
|
StructFields.push_back(type);
|
|
|
|
type = va_arg(ap, llvm::Type*);
|
|
|
|
}
|
|
|
|
return StructType::get(StructFields);
|
|
|
|
}
|
|
|
|
|
2009-07-01 01:50:28 +08:00
|
|
|
// ArrayType accessors
|
|
|
|
ArrayType* LLVMContext::getArrayType(const Type* ElementType,
|
2009-07-02 06:33:26 +08:00
|
|
|
uint64_t NumElements) {
|
2009-07-01 01:50:28 +08:00
|
|
|
return ArrayType::get(ElementType, NumElements);
|
|
|
|
}
|
|
|
|
|
|
|
|
// PointerType accessors
|
|
|
|
PointerType* LLVMContext::getPointerType(const Type* ElementType,
|
2009-07-02 06:33:26 +08:00
|
|
|
unsigned AddressSpace) {
|
2009-07-01 01:50:28 +08:00
|
|
|
return PointerType::get(ElementType, AddressSpace);
|
|
|
|
}
|
|
|
|
|
2009-07-02 07:56:45 +08:00
|
|
|
PointerType* LLVMContext::getPointerTypeUnqual(const Type* ElementType) {
|
2009-07-01 01:50:28 +08:00
|
|
|
return PointerType::getUnqual(ElementType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// VectorType accessors
|
|
|
|
VectorType* LLVMContext::getVectorType(const Type* ElementType,
|
2009-07-02 06:33:26 +08:00
|
|
|
unsigned NumElements) {
|
2009-07-01 01:50:28 +08:00
|
|
|
return VectorType::get(ElementType, NumElements);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
VectorType* LLVMContext::getVectorTypeInteger(const VectorType* VTy) {
|
2009-07-01 01:50:28 +08:00
|
|
|
return VectorType::getInteger(VTy);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
VectorType* LLVMContext::getVectorTypeExtendedElement(const VectorType* VTy) {
|
2009-07-01 01:50:28 +08:00
|
|
|
return VectorType::getExtendedElementVectorType(VTy);
|
|
|
|
}
|
|
|
|
|
2009-07-02 06:33:26 +08:00
|
|
|
VectorType* LLVMContext::getVectorTypeTruncatedElement(const VectorType* VTy) {
|
2009-07-01 01:50:28 +08:00
|
|
|
return VectorType::getTruncatedElementVectorType(VTy);
|
|
|
|
}
|
2009-07-10 07:48:35 +08:00
|
|
|
|
|
|
|
const Type* LLVMContext::makeCmpResultType(const Type* opnd_type) {
|
|
|
|
if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) {
|
|
|
|
return getVectorType(Type::Int1Ty, vt->getNumElements());
|
|
|
|
}
|
|
|
|
return Type::Int1Ty;
|
|
|
|
}
|