return ::builder->Insert(new StoreInst(value, ptr, isVolatile, align));
}
+ Value *Nucleus::createStore(Constant *constant, Value *ptr, bool isVolatile, unsigned int align)
+ {
+ return ::builder->Insert(new StoreInst(constant, ptr, isVolatile, align));
+ }
+
Value *Nucleus::createGEP(Value *ptr, Value *index)
{
return ::builder->CreateGEP(ptr, index);
void Nucleus::addSwitchCase(llvm::Value *Switch, int Case, llvm::BasicBlock *Branch)
{
- static_cast<SwitchInst*>(Switch)->addCase(Nucleus::createConstantInt(Case), Branch);
+ static_cast<SwitchInst*>(Switch)->addCase(llvm::ConstantInt::get(Type::getInt32Ty(*::context), Case, true), Branch);
}
Value *Nucleus::createUnreachable()
return shuffle;
}
- const llvm::GlobalValue *Nucleus::getGlobalValueAtAddress(void *Addr)
+ llvm::Constant *Nucleus::createConstantPointer(const void *address, llvm::Type *Ty, bool isConstant, unsigned int Align)
{
- return ::executionEngine->getGlobalValueAtAddress(Addr);
- }
+ const GlobalValue *existingGlobal = ::executionEngine->getGlobalValueAtAddress(const_cast<void*>(address)); // FIXME: Const
- void Nucleus::addGlobalMapping(const llvm::GlobalValue *GV, void *Addr)
- {
- ::executionEngine->addGlobalMapping(GV, Addr);
- }
+ if(existingGlobal)
+ {
+ return (llvm::Constant*)existingGlobal;
+ }
- llvm::GlobalValue *Nucleus::createGlobalValue(llvm::Type *Ty, bool isConstant, unsigned int Align)
- {
- llvm::GlobalValue *global = new llvm::GlobalVariable(*::module, Ty, isConstant, llvm::GlobalValue::ExternalLinkage, 0, "");
+ GlobalValue *global = new GlobalVariable(*::module, Ty, isConstant, GlobalValue::ExternalLinkage, 0, "");
global->setAlignment(Align);
+ ::executionEngine->addGlobalMapping(global, const_cast<void*>(address));
+
return global;
}
return llvm::Constant::getNullValue(Ty);
}
- llvm::ConstantInt *Nucleus::createConstantInt(int64_t i)
+ llvm::Constant *Nucleus::createConstantInt(int64_t i)
{
return llvm::ConstantInt::get(Type::getInt64Ty(*::context), i, true);
}
- llvm::ConstantInt *Nucleus::createConstantInt(int i)
+ llvm::Constant *Nucleus::createConstantInt(int i)
{
return llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, true);
}
- llvm::ConstantInt *Nucleus::createConstantInt(unsigned int i)
+ llvm::Constant *Nucleus::createConstantInt(unsigned int i)
{
return llvm::ConstantInt::get(Type::getInt32Ty(*::context), i, false);
}
- llvm::ConstantInt *Nucleus::createConstantBool(bool b)
+ llvm::Constant *Nucleus::createConstantBool(bool b)
{
return llvm::ConstantInt::get(Type::getInt1Ty(*::context), b);
}
- llvm::ConstantInt *Nucleus::createConstantByte(signed char i)
+ llvm::Constant *Nucleus::createConstantByte(signed char i)
{
return llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, true);
}
- llvm::ConstantInt *Nucleus::createConstantByte(unsigned char i)
+ llvm::Constant *Nucleus::createConstantByte(unsigned char i)
{
return llvm::ConstantInt::get(Type::getInt8Ty(*::context), i, false);
}
- llvm::ConstantInt *Nucleus::createConstantShort(short i)
+ llvm::Constant *Nucleus::createConstantShort(short i)
{
return llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, true);
}
- llvm::ConstantInt *Nucleus::createConstantShort(unsigned short i)
+ llvm::Constant *Nucleus::createConstantShort(unsigned short i)
{
return llvm::ConstantInt::get(Type::getInt16Ty(*::context), i, false);
}
return Nucleus::createStore(value, address, false, alignment);
}
+ llvm::Value *LValue::storeValue(llvm::Constant *constant, unsigned int alignment) const
+ {
+ return Nucleus::createStore(constant, address, false, alignment);
+ }
+
llvm::Value *LValue::getAddress(llvm::Value *index) const
{
return Nucleus::createGEP(address, index);
namespace llvm
{
- class BasicBlock;
+ class Type;
class Value;
class Constant;
- class ConstantInt;
- class Type;
- class GlobalValue;
+ class BasicBlock;
}
namespace sw
// Memory instructions
static llvm::Value *createLoad(llvm::Value *ptr, bool isVolatile = false, unsigned int align = 0);
static llvm::Value *createStore(llvm::Value *value, llvm::Value *ptr, bool isVolatile = false, unsigned int align = 0);
+ static llvm::Value *createStore(llvm::Constant *constant, llvm::Value *ptr, bool isVolatile = false, unsigned int align = 0);
static llvm::Value *createGEP(llvm::Value *ptr, llvm::Value *index);
// Atomic instructions
static llvm::Value *createSwizzle(llvm::Value *val, unsigned char select);
static llvm::Value *createMask(llvm::Value *lhs, llvm::Value *rhs, unsigned char select);
- // Global values
- static const llvm::GlobalValue *getGlobalValueAtAddress(void *Addr);
- static void addGlobalMapping(const llvm::GlobalValue *GV, void *Addr);
- static llvm::GlobalValue *createGlobalValue(llvm::Type *Ty, bool isConstant, unsigned int Align);
- static llvm::Type *getPointerType(llvm::Type *ElementType);
-
// Constant values
static llvm::Constant *createNullValue(llvm::Type *Ty);
- static llvm::ConstantInt *createConstantInt(int64_t i);
- static llvm::ConstantInt *createConstantInt(int i);
- static llvm::ConstantInt *createConstantInt(unsigned int i);
- static llvm::ConstantInt *createConstantBool(bool b);
- static llvm::ConstantInt *createConstantByte(signed char i);
- static llvm::ConstantInt *createConstantByte(unsigned char i);
- static llvm::ConstantInt *createConstantShort(short i);
- static llvm::ConstantInt *createConstantShort(unsigned short i);
+ static llvm::Constant *createConstantInt(int64_t i);
+ static llvm::Constant *createConstantInt(int i);
+ static llvm::Constant *createConstantInt(unsigned int i);
+ static llvm::Constant *createConstantBool(bool b);
+ static llvm::Constant *createConstantByte(signed char i);
+ static llvm::Constant *createConstantByte(unsigned char i);
+ static llvm::Constant *createConstantShort(short i);
+ static llvm::Constant *createConstantShort(unsigned short i);
static llvm::Constant *createConstantFloat(float x);
static llvm::Value *createNullPointer(llvm::Type *Ty);
static llvm::Value *createConstantVector(llvm::Constant *const *Vals, unsigned NumVals);
+ static llvm::Constant *createConstantPointer(const void *external, llvm::Type *Ty, bool isConstant, unsigned int Align);
+
+ static llvm::Type *getPointerType(llvm::Type *ElementType);
private:
void optimize();
llvm::Value *loadValue(unsigned int alignment = 0) const;
llvm::Value *storeValue(llvm::Value *value, unsigned int alignment = 0) const;
+ llvm::Value *storeValue(llvm::Constant *constant, unsigned int alignment = 0) const;
llvm::Value *getAddress(llvm::Value *index) const;
protected:
template<class T>
Pointer<T>::Pointer(const void *external) : alignment((intptr_t)external & 0x0000000F ? 1 : 16)
{
- const llvm::GlobalValue *globalPointer = Nucleus::getGlobalValueAtAddress(const_cast<void*>(external)); // FIXME: Const
-
- if(!globalPointer)
- {
- globalPointer = Nucleus::createGlobalValue(T::getType(), false, alignment);
-
- Nucleus::addGlobalMapping(globalPointer, const_cast<void*>(external)); // FIXME: Const
- }
+ llvm::Constant *globalPointer = Nucleus::createConstantPointer(external, T::getType(), false, alignment);
- LValue::storeValue((llvm::Value*)globalPointer); // FIXME: Const
+ LValue::storeValue(globalPointer);
}
template<class T>