Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hpvm-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
hpvm-release
Commits
e496365b
Commit
e496365b
authored
10 years ago
by
kotsifa2
Browse files
Options
Downloads
Patches
Plain Diff
Added functions that change the data layout and the target triple.
parent
cd55e712
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
+62
-24
62 additions, 24 deletions
llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
with
62 additions
and
24 deletions
llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
+
62
−
24
View file @
e496365b
...
...
@@ -8,8 +8,10 @@
//===----------------------------------------------------------------------===//
#define ENABLE_ASSERTS
#define TARGET_PTX 32
#define DEBUG_TYPE "DFG2LLVM_NVPTX"
#include
"llvm/IR/DataLayout.h"
#include
"llvm/IR/Module.h"
#include
"llvm/Pass.h"
#include
"llvm/Support/InstIterator.h"
...
...
@@ -25,6 +27,13 @@ using namespace builddfg;
//STATISTIC(IntrinsicCounter, "Counts number of visc intrinsics greeted");
namespace
{
// Helper function declarations
void
changeDataLayout
(
Module
&
);
void
changeTargetTriple
(
Module
&
);
std
::
string
convertInt
(
int
);
void
findReturnInst
(
Function
*
,
std
::
vector
<
ReturnInst
*>
&
);
// DFG2LLVM_NVPTX - The first implementation.
struct
DFG2LLVM_NVPTX
:
public
ModulePass
{
static
char
ID
;
// Pass identification, replacement for typeid
...
...
@@ -61,8 +70,6 @@ namespace {
//Functions
void
addReturnValueArgs
(
Function
*
F
);
Argument
*
getArgumentFromEnd
(
Function
*
F
,
unsigned
offset
);
Argument
*
getArgumentAt
(
Function
*
F
,
unsigned
offset
);
void
codeGen
(
DFInternalNode
*
N
);
void
codeGen
(
DFLeafNode
*
N
);
...
...
@@ -146,9 +153,8 @@ namespace {
IntrinsicInst
*
ArgII
;
DFNode
*
ArgDFNode
;
/******************************************************************************
* Handle VISC Query intrinsics *
******************************************************************************/
/************************ Handle VISC Query intrinsics ************************/
switch
(
II
->
getIntrinsicID
())
{
/**************************** llvm.visc.getNode() *****************************/
case
Intrinsic
::
visc_getNode
:
{
...
...
@@ -381,22 +387,6 @@ namespace {
return
true
;
}
std
::
string
convertInt
(
int
number
)
{
std
::
stringstream
ss
;
//create a stringstream
ss
<<
number
;
//add number to the stream
return
ss
.
str
();
//return a string with the contents of the stream
}
void
findReturnInst
(
Function
*
F
,
std
::
vector
<
ReturnInst
*>
&
ReturnInstVec
)
{
for
(
inst_iterator
i
=
inst_begin
(
F
),
e
=
inst_end
(
F
);
i
!=
e
;
++
i
)
{
Instruction
*
I
=
&
(
*
i
);
ReturnInst
*
RI
=
dyn_cast
<
ReturnInst
>
(
I
);
if
(
RI
)
{
ReturnInstVec
.
push_back
(
RI
);
}
}
}
void
CodeGenTraversal
::
addReturnValueArgs
(
Function
*
F
)
{
// FIXME: Maybe do that using the Node?
...
...
@@ -453,7 +443,7 @@ namespace {
check
++
;
}
DEBUG
(
errs
()
<<
"
\t
check = "
<<
check
<<
"
\t
initialNumParams = "
<<
initialNumParams
<<
"
\n
"
);
//
DEBUG(errs() << "\tcheck = " << check << "\tinitialNumParams = " << initialNumParams << "\n");
assert
(
check
==
initialNumParams
);
DEBUG
(
errs
()
<<
"
\t
Replacing Return statements
\n
"
);
...
...
@@ -480,10 +470,8 @@ namespace {
}
DEBUG
(
errs
()
<<
"
\t
Replaced return statements
\n
"
);
// Adding new arguments to the function argument list, would not change the
// function type. We need to change the type of this function to reflect the
// added arguments
...
...
@@ -496,6 +484,56 @@ namespace {
}
/******************************************************************************
* Helper functions *
******************************************************************************/
// Changes the data layout of the Module to be compiled with NVPTX backend
// TODO: Figure out when to call it, probably after duplicating the modules
void
changeDataLayout
(
Module
&
M
)
{
std
::
string
nvptx32_layoutStr
=
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
;
std
::
string
nvptx64_layoutStr
=
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
;
if
(
TARGET_PTX
==
32
)
M
.
setDataLayout
(
StringRef
(
nvptx32_layoutStr
));
else
if
(
TARGET_PTX
==
64
)
M
.
setDataLayout
(
StringRef
(
nvptx64_layoutStr
));
else
assert
(
false
&&
"Invalid PTX target"
);
return
;
}
void
changeTargetTriple
(
Module
&
M
)
{
std
::
string
nvptx32_TargetTriple
=
"nvptx--nvidiacl"
;
std
::
string
nvptx64_TargetTriple
=
"nvptx64--nvidiacl"
;
if
(
TARGET_PTX
==
32
)
M
.
setTargetTriple
(
StringRef
(
nvptx32_TargetTriple
));
else
if
(
TARGET_PTX
==
64
)
M
.
setTargetTriple
(
StringRef
(
nvptx64_TargetTriple
));
else
assert
(
false
&&
"Invalid PTX target"
);
return
;
}
// Helper function, convert int to string
std
::
string
convertInt
(
int
number
)
{
std
::
stringstream
ss
;
//create a stringstream
ss
<<
number
;
//add number to the stream
return
ss
.
str
();
//return a string with the contents of the stream
}
// Helper function, populate a vector with all return statements in a function
void
findReturnInst
(
Function
*
F
,
std
::
vector
<
ReturnInst
*>
&
ReturnInstVec
)
{
for
(
inst_iterator
i
=
inst_begin
(
F
),
e
=
inst_end
(
F
);
i
!=
e
;
++
i
)
{
Instruction
*
I
=
&
(
*
i
);
ReturnInst
*
RI
=
dyn_cast
<
ReturnInst
>
(
I
);
if
(
RI
)
{
ReturnInstVec
.
push_back
(
RI
);
}
}
}
}
// End of namespace
char
DFG2LLVM_NVPTX
::
ID
=
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment