Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F4820027
transformersaturation.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Aug 24, 5:48 AM
Size
2 KB
Mime Type
text/x-c++
Expires
Wed, Aug 26, 5:48 AM (22 h, 54 m)
Engine
blob
Format
Raw Data
Handle
284104
Attached To
rXR Xreate
transformersaturation.cpp
View Options
/*
* transformersaturation.cpp
*
* Author: pgess <v.melnychenko@xreate.org>
* Created on March 25, 2017, 10:06 PM
*/
#include "transformersaturation.h"
#include "llvmlayer.h"
using namespace llvm;
namespace xreate { namespace compilation {
TransformerSaturation::TransformerSaturation(llvm::BasicBlock* allocationBlock, TransformationsManager* manager)
: man(manager), blockAllocation(allocationBlock){
llvm::Type* tyInt1 = llvm::Type::getInt1Ty(llvm::getGlobalContext());
constTrue = llvm::ConstantInt::get(tyInt1, 1);
constFalse = llvm::ConstantInt::get(tyInt1, 0);
if (man->exists<TransformerSaturation>()){
oldInstance = man->update(this);
} else {
man->registerTransformer("break", this);
}
}
TransformerSaturation::~TransformerSaturation(){
if (oldInstance) {
man->update(oldInstance);
} else {
man->unregisterTransformer("break", this);
}
}
llvm::Value*
TransformerSaturation::transform(const Expression& expression, llvm::Value* raw, const Context& ctx){
processBreak(ctx);
return raw;
}
void
TransformerSaturation::processBreak(const Context& ctx){
allocateFlag(ctx);
//show the saturation flag
llvm::IRBuilder<>& builder = ctx.pass->man->llvm->builder;
builder.CreateStore(constTrue, flagSaturation, true);
}
void
TransformerSaturation::allocateFlag(const Context& ctx){
//allocation of saturation flag
llvm::Type* tyInt1 = llvm::Type::getInt1Ty(llvm::getGlobalContext());
IRBuilder<> builder(blockAllocation, blockAllocation->getFirstInsertionPt());
flagSaturation = builder.CreateAlloca(tyInt1, constTrue, "flagSaturation");
builder.CreateStore(constFalse, flagSaturation, true);
}
bool
TransformerSaturation::insertSaturationChecks(llvm::BasicBlock* blockContinue, llvm::BasicBlock* blockExit, const Context& ctx){
if (!flagSaturation) return false;
llvm::IRBuilder<>& builder = ctx.pass->man->llvm->builder;
builder.CreateCondBr(builder.CreateLoad(flagSaturation), blockExit, blockContinue);
return true;
}
} }
Event Timeline
Log In to Comment