SlideShare a Scribd company logo
1 of 12
Download to read offline
This is my code:
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Instructions.h"
#include "llvm/ADT/BitVector.h"
#include <unordered_map>
#include <queue>
using namespace std;
using namespace llvm;
namespace {
struct LivenessInfo {
BitVector liveIn;
BitVector liveOut;
};
// This method implements what the pass does
void visitor(Function &F){
string func_name = "main";
errs() << "Liveness analysis for function: " << F.getName() << "n";
// Process each basic block in the function and initialize the live-out and live-in sets
unordered_map<BasicBlock*, LivenessInfo> blockInfo;
BitVector initialLiveOut(F.arg_size() + F.getBasicBlockList().size(), false);
for (auto& basic_block : F) {
LivenessInfo info;
info.liveOut = initialLiveOut;
info.liveIn.resize(F.arg_size() + F.getBasicBlockList().size(), false); // initialize live-in set to
empty
blockInfo[&basic_block] = info;
}
// Creates a worklist of basic blocks to process, starting with the exit block
queue<BasicBlock*> worklist;
auto exitBlock = &F.back();
auto& exitInfo = blockInfo[exitBlock];
worklist.push(exitBlock);
exitInfo.liveOut = BitVector(initialLiveOut.size(), false); // initialize live-out set for exit block to
empty
// Compute the live-out set for each basic block
while (!worklist.empty()) {
auto block = worklist.front();
worklist.pop();
// Compute the live-out set by taking the union of the live-in sets of successors
auto& info = blockInfo[block];
for (auto it = succ_begin(block); it != succ_end(block); ++it) {
auto& succInfo = blockInfo[*it];
info.liveOut |= succInfo.liveIn;
}
// Compute the live-in set based on the live-out set and the instructions in the block
BitVector liveIn(info.liveOut);
for (auto it = block->rbegin(); it != block->rend(); ++it) {
auto inst = &*it;
// Remove variables defined by the instruction from the live-in set
if (auto store = dyn_cast<StoreInst>(inst)) {
auto var = store->getPointerOperand();
size_t varIndex = F.arg_size() + var->getName().substr(1).getAsInteger(10, varIndex);
liveIn.reset(varIndex);
}
// Add variables used by the instruction to the live-in set
for (auto op = inst->op_begin(); op != inst->op_end(); ++op) {
if (auto var = dyn_cast<Instruction>(*op)) {
size_t varIndex = F.arg_size() + var->getName().substr(1).getAsInteger(10, varIndex);
liveIn.set(varIndex);
}
}
}
// Update the live-in set for the current block
info.liveIn = liveIn;
// Add the predecessors of the block to the worklist, if not already processed
for (auto it = pred_begin(block); it != pred_end(block); ++it) {
auto predBlock = *it;
if (blockInfo[predBlock].liveOut != liveIn) {
worklist.push(predBlock);
}
}
}
// Print the live-in and live-out sets for each basic block
for (auto& basic_block : F) {
errs() << "-----" << basic_block.getName() << "-----" << "n";
auto& info = blockInfo[&basic_block];
errs() << "UEVAR: ";
for (int i = 0; i < F.arg_size(); i++) {
if (info.liveIn[i]) {
auto arg = F.getArg(i);
errs() << arg->getName() << " ";
}
}
errs() << "nVARKILL: ";
for (int i = 0; i < F.arg_size(); i++) {
if (info.liveOut[i] && info.liveIn[i]) {
auto arg = F.getArg(i);
errs() << arg->getName() << " ";
}
}
errs() << "nLIVEOUT: ";
for (int i = 0; i < F.arg_size(); i++) {
if (info.liveOut[i]) {
auto arg = F.getArg(i);
errs() << arg->getName() << " ";
}
}
errs() << "n";
}
}
}
struct ValueNumberingPass : public PassInfoMixin<ValueNumberingPass> {
// The first argument of the run() function defines on what level
// of granularity your pass will run (e.g. Module, Function).
// The second argument is the corresponding AnalysisManager
// (e.g ModuleAnalysisManager, FunctionAnalysisManager)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
visitor(F);
return PreservedAnalyses::all();
}
static bool isRequired() { return true; }
};
//-----------------------------------------------------------------------------
// New PM Registration
//-----------------------------------------------------------------------------
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
return {
LLVM_PLUGIN_API_VERSION, "ValueNumberingPass", LLVM_VERSION_STRING,
[](PassBuilder &PB) {
PB.registerPipelineParsingCallback(
[](StringRef Name, FunctionPassManager &FPM,
ArrayRef<PassBuilder::PipelineElement>) {
if (Name == "value-numbering") {
FPM.addPass(ValueNumberingPass());
return true;
}
return false;
});
}};
}
I am running the pass with this input file:
; ModuleID = 'test1.c'
source_filename = "test1.c"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-
S128"
target triple = "x86_64-apple-macosx12.0.0"
; Function Attrs: noinline nounwind optnone ssp uwtable
define void @test() #0 {
entry:
%a = alloca i32, align 4
%b = alloca i32, align 4
%c = alloca i32, align 4
%e = alloca i32, align 4
%0 = load i32, i32* %b, align 4
%1 = load i32, i32* %c, align 4
%add = add nsw i32 %0, %1
store i32 %add, i32* %e, align 4
%2 = load i32, i32* %e, align 4
%cmp = icmp sgt i32 %2, 0
br i1 %cmp, label %if.then, label %if.else
if.then: ; preds = %entry
%3 = load i32, i32* %a, align 4
store i32 %3, i32* %e, align 4
br label %if.end
if.else: ; preds = %entry
%4 = load i32, i32* %b, align 4
%5 = load i32, i32* %c, align 4
%add1 = add nsw i32 %4, %5
store i32 %add1, i32* %a, align 4
br label %if.end
if.end: ; preds = %if.else, %if.then
%6 = load i32, i32* %e, align 4
%7 = load i32, i32* %c, align 4
%add2 = add nsw i32 %6, %7
store i32 %add2, i32* %a, align 4
ret void
}
attributes #0 = { noinline nounwind optnone ssp uwtable "frame-pointer"="all" "min-legal-
vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-
cpu"="penryn" "target-
features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-
cpu"="generic" }
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{i32 7, !"uwtable", i32 2}
!3 = !{i32 7, !"frame-pointer", i32 2}
!4 = !{!"Homebrew clang version 15.0.7"}
My output is this:
Liveness analysis for function: test
-----entry-----
UEVAR:
VARKILL:
LIVEOUT:
-----if.then-----
UEVAR:
VARKILL:
LIVEOUT:
-----if.else-----
UEVAR:
VARKILL:
LIVEOUT:
-----if.end-----
UEVAR:
VARKILL:
LIVEOUT:
Instead of this:
----- entry -----
UEVAR: b c
VARKILL: e
LIVEOUT: a b c e
----- if.then -----
UEVAR: a
VARKILL: e
LIVEOUT: c e
----- if.else -----
UEVAR: b c
VARKILL: a
LIVEOUT: c e
----- if.end -----
UEVAR: c e
VARKILL: a
LIVEOUT:
What Am I doing wrong?
----- entry -----
UEVAR: b c
VARKILL: e
LIVEOUT: a b c e
----- if.then -----
UEVAR: a
VARKILL: e
LIVEOUT: c e
----- if.else -----
UEVAR: b c
VARKILL: a
LIVEOUT: c e
----- if.end -----
UEVAR: c e
VARKILL: a
LIVEOUT:

More Related Content

Similar to This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf

VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
JavaOne 2016 -Emerging Web App Architectures using Java and node.js
JavaOne 2016 -Emerging Web App Architectures using Java and node.jsJavaOne 2016 -Emerging Web App Architectures using Java and node.js
JavaOne 2016 -Emerging Web App Architectures using Java and node.jsSteve Wallin
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptVisual Engineering
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdfmhande899
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
ESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowKrzysztof Szafranek
 
pt-query-digest は Perl!!
pt-query-digest は Perl!!pt-query-digest は Perl!!
pt-query-digest は Perl!!Takafumi ONAKA
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bChereCheek752
 
Writing DSLs with Parslet - Wicked Good Ruby Conf
Writing DSLs with Parslet - Wicked Good Ruby ConfWriting DSLs with Parslet - Wicked Good Ruby Conf
Writing DSLs with Parslet - Wicked Good Ruby ConfJason Garber
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineMatt Provost
 
Aspdevice - Asp Fast Crud introdution
Aspdevice - Asp Fast Crud introdutionAspdevice - Asp Fast Crud introdution
Aspdevice - Asp Fast Crud introdutionAdriano Mendes
 
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docxMARRY7
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6WebF
 
JSUG - Spring by Christoph Pickl
JSUG - Spring by Christoph PicklJSUG - Spring by Christoph Pickl
JSUG - Spring by Christoph PicklChristoph Pickl
 

Similar to This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf (20)

VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
JavaOne 2016 -Emerging Web App Architectures using Java and node.js
JavaOne 2016 -Emerging Web App Architectures using Java and node.jsJavaOne 2016 -Emerging Web App Architectures using Java and node.js
JavaOne 2016 -Emerging Web App Architectures using Java and node.js
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdf
 
Gps c
Gps cGps c
Gps c
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
ESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. Now
 
Library management system
Library management systemLibrary management system
Library management system
 
pt-query-digest は Perl!!
pt-query-digest は Perl!!pt-query-digest は Perl!!
pt-query-digest は Perl!!
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Vcs16
Vcs16Vcs16
Vcs16
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
 
My java file
My java fileMy java file
My java file
 
Writing DSLs with Parslet - Wicked Good Ruby Conf
Writing DSLs with Parslet - Wicked Good Ruby ConfWriting DSLs with Parslet - Wicked Good Ruby Conf
Writing DSLs with Parslet - Wicked Good Ruby Conf
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command Line
 
Aspdevice - Asp Fast Crud introdution
Aspdevice - Asp Fast Crud introdutionAspdevice - Asp Fast Crud introdution
Aspdevice - Asp Fast Crud introdution
 
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
JSUG - Spring by Christoph Pickl
JSUG - Spring by Christoph PicklJSUG - Spring by Christoph Pickl
JSUG - Spring by Christoph Pickl
 

More from EricvtJFraserr

Trade protectionism is a policy that protects domestic industries from.pdf
Trade protectionism is a policy that protects domestic industries from.pdfTrade protectionism is a policy that protects domestic industries from.pdf
Trade protectionism is a policy that protects domestic industries from.pdfEricvtJFraserr
 
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdf
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdftrace a calciol molecule (inactive D) from the liver to the kidney- Th.pdf
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdfEricvtJFraserr
 
TP fraudulently failed to report income that resulted in a $100-000 un.pdf
TP fraudulently failed to report income that resulted in a $100-000 un.pdfTP fraudulently failed to report income that resulted in a $100-000 un.pdf
TP fraudulently failed to report income that resulted in a $100-000 un.pdfEricvtJFraserr
 
Topographic Maps 1- Define topographic map- 2- Describe 3 different.pdf
Topographic Maps 1-  Define topographic map-  2-  Describe 3 different.pdfTopographic Maps 1-  Define topographic map-  2-  Describe 3 different.pdf
Topographic Maps 1- Define topographic map- 2- Describe 3 different.pdfEricvtJFraserr
 
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdfTopic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdfEricvtJFraserr
 
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdfTotal tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdfEricvtJFraserr
 
Topographic Maps 10- What is the scale of a map- Give some examples.pdf
Topographic Maps  10-  What is the scale of a map-  Give some examples.pdfTopographic Maps  10-  What is the scale of a map-  Give some examples.pdf
Topographic Maps 10- What is the scale of a map- Give some examples.pdfEricvtJFraserr
 
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdfToast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdfEricvtJFraserr
 
To do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdfTo do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdfEricvtJFraserr
 
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdfTo determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdfEricvtJFraserr
 
To clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdfTo clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdfEricvtJFraserr
 
To avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdfTo avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdfEricvtJFraserr
 
Three Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdfThree Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdfEricvtJFraserr
 
This year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdfThis year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdfEricvtJFraserr
 
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdfThis Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdfEricvtJFraserr
 
This map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdfThis map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdfEricvtJFraserr
 
This medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdfThis medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdfEricvtJFraserr
 
This map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdfThis map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdfEricvtJFraserr
 
This map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdfThis map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdfEricvtJFraserr
 
Things wrong with my code- 1- The notes do not play when i press down.pdf
Things wrong with my code- 1- The notes do not play when i press down.pdfThings wrong with my code- 1- The notes do not play when i press down.pdf
Things wrong with my code- 1- The notes do not play when i press down.pdfEricvtJFraserr
 

More from EricvtJFraserr (20)

Trade protectionism is a policy that protects domestic industries from.pdf
Trade protectionism is a policy that protects domestic industries from.pdfTrade protectionism is a policy that protects domestic industries from.pdf
Trade protectionism is a policy that protects domestic industries from.pdf
 
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdf
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdftrace a calciol molecule (inactive D) from the liver to the kidney- Th.pdf
trace a calciol molecule (inactive D) from the liver to the kidney- Th.pdf
 
TP fraudulently failed to report income that resulted in a $100-000 un.pdf
TP fraudulently failed to report income that resulted in a $100-000 un.pdfTP fraudulently failed to report income that resulted in a $100-000 un.pdf
TP fraudulently failed to report income that resulted in a $100-000 un.pdf
 
Topographic Maps 1- Define topographic map- 2- Describe 3 different.pdf
Topographic Maps 1-  Define topographic map-  2-  Describe 3 different.pdfTopographic Maps 1-  Define topographic map-  2-  Describe 3 different.pdf
Topographic Maps 1- Define topographic map- 2- Describe 3 different.pdf
 
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdfTopic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
Topic 5 1- Explain the concepts of linkage disequilibrium and haplotyp.pdf
 
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdfTotal tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
Total tactory overlisad is $1-200-000- Ansume tho following activity c.pdf
 
Topographic Maps 10- What is the scale of a map- Give some examples.pdf
Topographic Maps  10-  What is the scale of a map-  Give some examples.pdfTopographic Maps  10-  What is the scale of a map-  Give some examples.pdf
Topographic Maps 10- What is the scale of a map- Give some examples.pdf
 
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdfToast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
Toast and Jelly Corp-'s payroll for the pay period ended October 31- 2.pdf
 
To do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdfTo do- Use the drop down list in column E to determine which entity ty.pdf
To do- Use the drop down list in column E to determine which entity ty.pdf
 
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdfTo determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
To determine the mechanism by which N-WASp mediates activation by Cdc4.pdf
 
To clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdfTo clarify- this is specifically for Java- Write a program that asks t.pdf
To clarify- this is specifically for Java- Write a program that asks t.pdf
 
To avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdfTo avoid typos- copy and paste the portions of the IP address that wil.pdf
To avoid typos- copy and paste the portions of the IP address that wil.pdf
 
Three Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdfThree Ways Heat Energy can move from one place to another (Define and.pdf
Three Ways Heat Energy can move from one place to another (Define and.pdf
 
This year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdfThis year Luke has calculated his gross tax liability at $1-900- Luke.pdf
This year Luke has calculated his gross tax liability at $1-900- Luke.pdf
 
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdfThis Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
This Scottish economist was highly critical of the Mercantilists- A-Ad.pdf
 
This map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdfThis map shows the location and size of earthquakes in and around Turk.pdf
This map shows the location and size of earthquakes in and around Turk.pdf
 
This medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdfThis medieval social- cultural- and economic movement that involved de.pdf
This medieval social- cultural- and economic movement that involved de.pdf
 
This map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdfThis map shows a summary of earthquakes that occurred across the globe.pdf
This map shows a summary of earthquakes that occurred across the globe.pdf
 
This map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdfThis map from the USGS' Earthquake Hazards Program website shows earth.pdf
This map from the USGS' Earthquake Hazards Program website shows earth.pdf
 
Things wrong with my code- 1- The notes do not play when i press down.pdf
Things wrong with my code- 1- The notes do not play when i press down.pdfThings wrong with my code- 1- The notes do not play when i press down.pdf
Things wrong with my code- 1- The notes do not play when i press down.pdf
 

Recently uploaded

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Recently uploaded (20)

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

This is my code- #include -llvm-IR-LegacyPassManager-h- #include -llv.pdf

  • 1. This is my code: #include "llvm/IR/LegacyPassManager.h" #include "llvm/Passes/PassPlugin.h" #include "llvm/Passes/PassBuilder.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/Instructions.h" #include "llvm/ADT/BitVector.h" #include <unordered_map> #include <queue> using namespace std; using namespace llvm; namespace { struct LivenessInfo { BitVector liveIn; BitVector liveOut; }; // This method implements what the pass does void visitor(Function &F){
  • 2. string func_name = "main"; errs() << "Liveness analysis for function: " << F.getName() << "n"; // Process each basic block in the function and initialize the live-out and live-in sets unordered_map<BasicBlock*, LivenessInfo> blockInfo; BitVector initialLiveOut(F.arg_size() + F.getBasicBlockList().size(), false); for (auto& basic_block : F) { LivenessInfo info; info.liveOut = initialLiveOut; info.liveIn.resize(F.arg_size() + F.getBasicBlockList().size(), false); // initialize live-in set to empty blockInfo[&basic_block] = info; } // Creates a worklist of basic blocks to process, starting with the exit block queue<BasicBlock*> worklist; auto exitBlock = &F.back(); auto& exitInfo = blockInfo[exitBlock]; worklist.push(exitBlock); exitInfo.liveOut = BitVector(initialLiveOut.size(), false); // initialize live-out set for exit block to empty // Compute the live-out set for each basic block
  • 3. while (!worklist.empty()) { auto block = worklist.front(); worklist.pop(); // Compute the live-out set by taking the union of the live-in sets of successors auto& info = blockInfo[block]; for (auto it = succ_begin(block); it != succ_end(block); ++it) { auto& succInfo = blockInfo[*it]; info.liveOut |= succInfo.liveIn; } // Compute the live-in set based on the live-out set and the instructions in the block BitVector liveIn(info.liveOut); for (auto it = block->rbegin(); it != block->rend(); ++it) { auto inst = &*it; // Remove variables defined by the instruction from the live-in set if (auto store = dyn_cast<StoreInst>(inst)) { auto var = store->getPointerOperand(); size_t varIndex = F.arg_size() + var->getName().substr(1).getAsInteger(10, varIndex); liveIn.reset(varIndex); } // Add variables used by the instruction to the live-in set for (auto op = inst->op_begin(); op != inst->op_end(); ++op) {
  • 4. if (auto var = dyn_cast<Instruction>(*op)) { size_t varIndex = F.arg_size() + var->getName().substr(1).getAsInteger(10, varIndex); liveIn.set(varIndex); } } } // Update the live-in set for the current block info.liveIn = liveIn; // Add the predecessors of the block to the worklist, if not already processed for (auto it = pred_begin(block); it != pred_end(block); ++it) { auto predBlock = *it; if (blockInfo[predBlock].liveOut != liveIn) { worklist.push(predBlock); } } } // Print the live-in and live-out sets for each basic block for (auto& basic_block : F) { errs() << "-----" << basic_block.getName() << "-----" << "n"; auto& info = blockInfo[&basic_block]; errs() << "UEVAR: ";
  • 5. for (int i = 0; i < F.arg_size(); i++) { if (info.liveIn[i]) { auto arg = F.getArg(i); errs() << arg->getName() << " "; } } errs() << "nVARKILL: "; for (int i = 0; i < F.arg_size(); i++) { if (info.liveOut[i] && info.liveIn[i]) { auto arg = F.getArg(i); errs() << arg->getName() << " "; } } errs() << "nLIVEOUT: "; for (int i = 0; i < F.arg_size(); i++) { if (info.liveOut[i]) { auto arg = F.getArg(i); errs() << arg->getName() << " "; } } errs() << "n"; } }
  • 6. } struct ValueNumberingPass : public PassInfoMixin<ValueNumberingPass> { // The first argument of the run() function defines on what level // of granularity your pass will run (e.g. Module, Function). // The second argument is the corresponding AnalysisManager // (e.g ModuleAnalysisManager, FunctionAnalysisManager) PreservedAnalyses run(Function &F, FunctionAnalysisManager &) { visitor(F); return PreservedAnalyses::all(); } static bool isRequired() { return true; } }; //----------------------------------------------------------------------------- // New PM Registration //----------------------------------------------------------------------------- extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo() { return { LLVM_PLUGIN_API_VERSION, "ValueNumberingPass", LLVM_VERSION_STRING, [](PassBuilder &PB) {
  • 7. PB.registerPipelineParsingCallback( [](StringRef Name, FunctionPassManager &FPM, ArrayRef<PassBuilder::PipelineElement>) { if (Name == "value-numbering") { FPM.addPass(ValueNumberingPass()); return true; } return false; }); }}; } I am running the pass with this input file: ; ModuleID = 'test1.c' source_filename = "test1.c" target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64- S128" target triple = "x86_64-apple-macosx12.0.0" ; Function Attrs: noinline nounwind optnone ssp uwtable define void @test() #0 { entry: %a = alloca i32, align 4 %b = alloca i32, align 4
  • 8. %c = alloca i32, align 4 %e = alloca i32, align 4 %0 = load i32, i32* %b, align 4 %1 = load i32, i32* %c, align 4 %add = add nsw i32 %0, %1 store i32 %add, i32* %e, align 4 %2 = load i32, i32* %e, align 4 %cmp = icmp sgt i32 %2, 0 br i1 %cmp, label %if.then, label %if.else if.then: ; preds = %entry %3 = load i32, i32* %a, align 4 store i32 %3, i32* %e, align 4 br label %if.end if.else: ; preds = %entry %4 = load i32, i32* %b, align 4 %5 = load i32, i32* %c, align 4 %add1 = add nsw i32 %4, %5 store i32 %add1, i32* %a, align 4 br label %if.end if.end: ; preds = %if.else, %if.then
  • 9. %6 = load i32, i32* %e, align 4 %7 = load i32, i32* %c, align 4 %add2 = add nsw i32 %6, %7 store i32 %add2, i32* %a, align 4 ret void } attributes #0 = { noinline nounwind optnone ssp uwtable "frame-pointer"="all" "min-legal- vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target- cpu"="penryn" "target- features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune- cpu"="generic" } !llvm.module.flags = !{!0, !1, !2, !3} !llvm.ident = !{!4} !0 = !{i32 1, !"wchar_size", i32 4} !1 = !{i32 7, !"PIC Level", i32 2} !2 = !{i32 7, !"uwtable", i32 2} !3 = !{i32 7, !"frame-pointer", i32 2} !4 = !{!"Homebrew clang version 15.0.7"} My output is this: Liveness analysis for function: test -----entry-----
  • 11. LIVEOUT: c e ----- if.else ----- UEVAR: b c VARKILL: a LIVEOUT: c e ----- if.end ----- UEVAR: c e VARKILL: a LIVEOUT: What Am I doing wrong? ----- entry ----- UEVAR: b c VARKILL: e LIVEOUT: a b c e ----- if.then ----- UEVAR: a VARKILL: e LIVEOUT: c e ----- if.else ----- UEVAR: b c VARKILL: a LIVEOUT: c e ----- if.end -----
  • 12. UEVAR: c e VARKILL: a LIVEOUT: