Ignore:
Timestamp:
Feb 18, 2015, 3:56:47 PM (5 years ago)
Author:
nmedfort
Message:

Many memory deallocation fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4438 r4510  
    5858#include <llvm/Support/MemoryBuffer.h>
    5959#include <llvm/IR/IRBuilder.h>
    60 #include "llvm/Support/CommandLine.h"
     60#include <llvm/Support/CommandLine.h>
     61#include <llvm/ADT/Twine.h>
    6162#include <iostream>
    6263
     
    9394, mOutputAddrPtr(nullptr)
    9495, mMaxNestingDepth(0)
     96, mPrintRegisterFunction(nullptr)
    9597{
    9698    //Create the jit execution engine.up
     
    103105PabloCompiler::~PabloCompiler()
    104106{
    105     delete mMod;
     107    // delete mMod;
    106108}
    107109   
     
    158160        Value* indices[] = {b.getInt64(0), b.getInt32(i)};
    159161        Value * gep = b.CreateGEP(mBasisBitsAddr, indices);
    160         LoadInst * basisBit = b.CreateAlignedLoad(gep, BLOCK_SIZE/8, false, mBasisBits[i]->getName()->str());
     162        LoadInst * basisBit = b.CreateAlignedLoad(gep, BLOCK_SIZE/8, false, mBasisBits[i]->getName()->to_string());
    161163        mMarkerMap.insert(std::make_pair(mBasisBits[i], basisBit));
    162164    }
     
    190192    #endif
    191193
    192     //Use the pass manager to run optimizations on the function.
    193     FunctionPassManager fpm(mMod);
    194  #ifdef USE_LLVM_3_5
    195     mMod->setDataLayout(mExecutionEngine->getDataLayout());
    196     // Set up the optimizer pipeline.  Start with registering info about how the target lays out data structures.
    197     fpm.add(new DataLayoutPass(mMod));
    198 #endif
    199 #ifdef USE_LLVM_3_4
    200     fpm.add(new DataLayout(*mExecutionEngine->getDataLayout()));
    201 #endif
    202     fpm.doInitialization();
    203     fpm.run(*mFunction);
    204 
    205194    mExecutionEngine->finalizeObject();
    206195
     
    264253{
    265254    //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
    266     mFunc_print_register = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(getGlobalContext()), mBitBlockType, NULL);
    267     mExecutionEngine->addGlobalMapping(cast<GlobalValue>(mFunc_print_register), (void *)&wrapped_print_register);
     255    mPrintRegisterFunction = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(getGlobalContext()), mBitBlockType, NULL);
     256    mExecutionEngine->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
    268257    // to call->  b.CreateCall(mFunc_print_register, unicode_category);
    269258
     
    463452        const String * callee = mapping.first;
    464453        //std::cerr << callee->str() << " to be declared\n";
    465         auto ei = mExternalMap.find(callee->str());
     454        auto ei = mExternalMap.find(callee->value());
    466455        if (ei != mExternalMap.end()) {
    467456            void * fn_ptr = ei->second;
    468457            //std::cerr << "Ptr found:" <<  std::hex << ((intptr_t) fn_ptr) << std::endl;
    469             Value * externalValue = mMod->getOrInsertFunction(callee->str(), mBitBlockType, mBasisBitsInputPtr, NULL);
     458            Value * externalValue = mMod->getOrInsertFunction(callee->value(), mBitBlockType, mBasisBitsInputPtr, NULL);
    470459            if (LLVM_UNLIKELY(externalValue == nullptr)) {
    471                 throw std::runtime_error("Could not create static method call for external function \"" + callee->str() + "\"");
     460                throw std::runtime_error("Could not create static method call for external function \"" + callee->to_string() + "\"");
    472461            }
    473462            mExecutionEngine->addGlobalMapping(cast<GlobalValue>(externalValue), fn_ptr);
     
    475464        }
    476465        else {
    477             throw std::runtime_error("External function \"" + callee->str() + "\" not installed");
     466            throw std::runtime_error("External function \"" + callee->to_string() + "\" not installed");
    478467        }
    479468    }
     
    607596        //End Block
    608597        IRBuilder<> bEnd(ifEndBlock);
    609         for (const Statement * a : ifStatement->getDefined()) {
    610             PHINode * phi = bEnd.CreatePHI(mBitBlockType, 2, a->getName()->str());
    611             auto f = mMarkerMap.find(a);
     598        for (const PabloAST * node : ifStatement->getDefined()) {
     599            const Assign * assign = cast<Assign>(node);
     600            PHINode * phi = bEnd.CreatePHI(mBitBlockType, 2, assign->getName()->value());
     601            auto f = mMarkerMap.find(assign);
    612602            assert (f != mMarkerMap.end());
    613603            phi->addIncoming(mZeroInitializer, ifEntryBlock);
    614604            phi->addIncoming(f->second, mBasicBlock);
    615             mMarkerMap[a] = phi;
     605            mMarkerMap[assign] = phi;
    616606        }
    617607        // Create the phi Node for the summary variable.
     
    698688        // and for any Next nodes in the loop body
    699689        for (const Next * n : nextNodes) {
    700             PHINode * phi = bCond.CreatePHI(mBitBlockType, 2, n->getName()->str());
     690            PHINode * phi = bCond.CreatePHI(mBitBlockType, 2, n->getName()->value());
    701691            auto f = mMarkerMap.find(n->getInitial());
    702692            assert (f != mMarkerMap.end());
     
    754744            auto ci = mCalleeMap.find(call->getCallee());
    755745            if (LLVM_UNLIKELY(ci == mCalleeMap.end())) {
    756                 throw std::runtime_error("Unexpected error locating static function for \"" + call->getCallee()->str() + "\"");
     746                throw std::runtime_error("Unexpected error locating static function for \"" + call->getCallee()->to_string() + "\"");
    757747            }
    758748            mi = mMarkerMap.insert(std::make_pair(call, b.CreateCall(ci->second, mBasisBitsAddr))).first;
Note: See TracChangeset for help on using the changeset viewer.