Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengyang92 committed Jan 15, 2020
1 parent 05a97b6 commit 440b437
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 40 deletions.
23 changes: 3 additions & 20 deletions lib/Codegen/Codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ llvm::Value *Codegen::getValueHelper(Inst *I, std::map<Inst *, llvm::Value *> &C
std::vector<BasicBlock *> Preds;
std::vector<Value *> Incomes;
BasicBlock *E = Builder.GetInsertBlock();
BasicBlock *NextBB = BasicBlock::Create(Context, "next", F);
BasicBlock *NextBB = BasicBlock::Create(Context, "cont", F);

BasicBlock *DefaultNextBB;
for (int i = 0 ; i < I->Ops.size(); i ++) {
Expand All @@ -86,6 +86,7 @@ llvm::Value *Codegen::getValueHelper(Inst *I, std::map<Inst *, llvm::Value *> &C
Incomes.emplace_back(V0);
if (i == 0) DefaultNextBB = BB;
}


Builder.SetInsertPoint(E);
Value *D = BM[I->B];
Expand Down Expand Up @@ -370,32 +371,14 @@ static std::map<Inst *, Value *> GetArgsMapping(const InstContext &IC,


llvm::Function *Codegen::getFunction(Inst *I, const InstContext &IC) {

F = Builder.GetInsertBlock()->getParent();
auto PhiDet = M->getOrInsertFunction("phi_det",
FunctionType::getInt32Ty(Context));

std::vector<llvm::Type *> ArgTypes = GetInputArgumentTypes(IC, Context);
// phi determinism



const auto FT = llvm::FunctionType::get(
/*Result=*/GetInstReturnType(Context, I),
/*Params=*/ArgTypes, /*isVarArg=*/false);

F = llvm::Function::Create(FT, llvm::Function::ExternalLinkage, "fun", M);

const std::map<Inst *, Value *> Args = GetArgsMapping(IC, F);

//const std::map<Inst *, Value *> Args = GetArgsMapping(IC, F);

BasicBlock *BB = BasicBlock::Create(Context, "entry", F);


std::vector<Block *> Blocks = souper::getBlocksFromPhis(I);
std::map<Block *, llvm::Value *> BlockMap;

Builder.SetInsertPoint(BB);
for (int i = 0 ; i < Blocks.size(); i ++) {
Value *V = Builder.CreateCall(PhiDet, {});
BlockMap[Blocks[i]] = V;
Expand Down
35 changes: 15 additions & 20 deletions tools/souper2llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,25 @@ int Work(const MemoryBufferRef &MB) {

llvm::LLVMContext Context;
llvm::Module Module("souper.ll", Context);
llvm::IRBuilder<> Builder(Context);

Function *F;
const std::vector<llvm::Type *> ArgTypes = GetInputArgumentTypes(IC, Context);
const auto FT = llvm::FunctionType::get(
/*Result=*/Codegen::GetInstReturnType(Context, RepRHS.Mapping.RHS),
/*Params=*/ArgTypes, /*isVarArg=*/false);

F = Function::Create(FT, Function::ExternalLinkage, "fun", &Module);
const std::map<Inst *, Value *> Args = GetArgsMapping(IC, F);

BasicBlock *BB = BasicBlock::Create(Context, "entry", F);

if (GenCF) {
F = Codegen(Context, &Module, Builder, /*DT*/ nullptr,
/*ReplacedInst*/ nullptr, {}, true).getFunction(RepRHS.Mapping.RHS, IC);
llvm::IRBuilder<> Builder(Context);
Builder.SetInsertPoint(BB);

if (GenCF) {
F = Codegen(Context, &Module, Builder, /*DT*/ nullptr, nullptr,
/*ReplacedInst*/ Args, true)
.getFunction(RepRHS.Mapping.RHS, IC);
} else {
const std::vector<llvm::Type *> ArgTypes = GetInputArgumentTypes(IC, Context);
const auto FT = llvm::FunctionType::get(
/*Result=*/Codegen::GetInstReturnType(Context, RepRHS.Mapping.RHS),
/*Params=*/ArgTypes, /*isVarArg=*/false);

F = Function::Create(FT, Function::ExternalLinkage, "fun", &Module);



BasicBlock *BB = BasicBlock::Create(Context, "entry", F);

llvm::IRBuilder<> Builder(Context);
Builder.SetInsertPoint(BB);
const std::map<Inst *, Value *> Args = GetArgsMapping(IC, F);

Value *RetVal = Codegen(Context, &Module, Builder, /*DT*/ nullptr,
/*ReplacedInst*/ nullptr, Args, false)
.getValue(RepRHS.Mapping.RHS);
Expand Down

0 comments on commit 440b437

Please sign in to comment.