[llvm] 649977c - Opaque pointer GEP fixes for BrainF example
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 18 18:26:05 PDT 2021
Author: David Blaikie
Date: 2021-07-18T18:25:54-07:00
New Revision: 649977c6d74072c07980fa6f88ab3c490f8b1263
URL: https://github.com/llvm/llvm-project/commit/649977c6d74072c07980fa6f88ab3c490f8b1263
DIFF: https://github.com/llvm/llvm-project/commit/649977c6d74072c07980fa6f88ab3c490f8b1263.diff
LOG: Opaque pointer GEP fixes for BrainF example
Added:
Modified:
llvm/examples/BrainF/BrainF.cpp
Removed:
################################################################################
diff --git a/llvm/examples/BrainF/BrainF.cpp b/llvm/examples/BrainF/BrainF.cpp
index ba9184df72ad1..11a752b1a5474 100644
--- a/llvm/examples/BrainF/BrainF.cpp
+++ b/llvm/examples/BrainF/BrainF.cpp
@@ -114,14 +114,13 @@ void BrainF::header(LLVMContext& C) {
//%arrmax = getelementptr i8 *%arr, i32 %d
if (comflag & flag_arraybounds) {
- ptr_arrmax = builder->
- CreateGEP(ptr_arr, ConstantInt::get(C, APInt(32, memtotal)), "arrmax");
+ ptr_arrmax = builder->CreateGEP(
+ Int8Ty, ptr_arr, ConstantInt::get(C, APInt(32, memtotal)), "arrmax");
}
//%head.%d = getelementptr i8 *%arr, i32 %d
- curhead = builder->CreateGEP(ptr_arr,
- ConstantInt::get(C, APInt(32, memtotal/2)),
- headreg);
+ curhead = builder->CreateGEP(
+ Int8Ty, ptr_arr, ConstantInt::get(C, APInt(32, memtotal / 2)), headreg);
//Function footer
@@ -195,6 +194,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
char c;
int loop;
int direction;
+ Type *Int8Ty = IntegerType::getInt8Ty(C);
while(cursym != SYM_EOF && cursym != SYM_ENDLOOP) {
// Write out commands
@@ -223,8 +223,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
case SYM_WRITE:
{
//%tape.%d = load i8 *%head.%d
- LoadInst *tape_0 =
- builder->CreateLoad(IntegerType::getInt8Ty(C), curhead, tapereg);
+ LoadInst *tape_0 = builder->CreateLoad(Int8Ty, curhead, tapereg);
//%tape.%d = sext i8 %tape.%d to i32
Value *tape_1 = builder->
@@ -244,9 +243,9 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
case SYM_MOVE:
{
//%head.%d = getelementptr i8 *%head.%d, i32 %d
- curhead = builder->
- CreateGEP(curhead, ConstantInt::get(C, APInt(32, curvalue)),
- headreg);
+ curhead = builder->CreateGEP(Int8Ty, curhead,
+ ConstantInt::get(C, APInt(32, curvalue)),
+ headreg);
//Error block for array out of bounds
if (comflag & flag_arraybounds)
@@ -276,8 +275,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
case SYM_CHANGE:
{
//%tape.%d = load i8 *%head.%d
- LoadInst *tape_0 =
- builder->CreateLoad(IntegerType::getInt8Ty(C), curhead, tapereg);
+ LoadInst *tape_0 = builder->CreateLoad(Int8Ty, curhead, tapereg);
//%tape.%d = add i8 %tape.%d, %d
Value *tape_1 = builder->
@@ -300,9 +298,8 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
builder->SetInsertPoint(bb_1);
// Make part of PHI instruction now, wait until end of loop to finish
- PHINode *phi_0 =
- PHINode::Create(PointerType::getUnqual(IntegerType::getInt8Ty(C)),
- 2, headreg, testbb);
+ PHINode *phi_0 = PHINode::Create(PointerType::getUnqual(Int8Ty), 2,
+ headreg, testbb);
phi_0->addIncoming(curhead, bb_0);
curhead = phi_0;
@@ -441,8 +438,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
Value *head_0 = phi;
//%tape.%d = load i8 *%head.%d
- LoadInst *tape_0 = new LoadInst(IntegerType::getInt8Ty(C), head_0,
- tapereg, testbb);
+ LoadInst *tape_0 = new LoadInst(Int8Ty, head_0, tapereg, testbb);
//%test.%d = icmp eq i8 %tape.%d, 0
ICmpInst *test_0 = new ICmpInst(*testbb, ICmpInst::ICMP_EQ, tape_0,
@@ -456,9 +452,8 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
builder->SetInsertPoint(bb_0);
//%head.%d = phi i8 *[%head.%d, %main.%d]
- PHINode *phi_1 = builder->
- CreatePHI(PointerType::getUnqual(IntegerType::getInt8Ty(C)), 1,
- headreg);
+ PHINode *phi_1 =
+ builder->CreatePHI(PointerType::getUnqual(Int8Ty), 1, headreg);
phi_1->addIncoming(head_0, testbb);
curhead = phi_1;
}
More information about the llvm-commits
mailing list