"vscode:/vscode.git/clone" did not exist on "cb170ac024a949f1f9614ffe6af1c38d972f7d48"
Commit 8ec57337 authored by dugupeiwen's avatar dugupeiwen
Browse files

adapt for DTK clang-14

parent 55ada7af
......@@ -16,9 +16,9 @@ add_library(
llvm_map_components_to_libnames(
llvm_libs # this name is magic, it is the variable in which the
# component linker info is stored.
#all
all
amdgpuasmparser
amdgpuasmprinter
# amdgpuasmprinter
amdgpucodegen
amdgpudesc
amdgpudisassembler
......@@ -45,5 +45,6 @@ set_target_properties(rocmlite PROPERTIES
# Add in test dir
# add_subdirectory(googletest)
add_subdirectory(test)
......@@ -11,7 +11,8 @@
#include "llvm/AsmParser/Parser.h"
#include "llvm/Bitcode/BitcodeWriterPass.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/CodeGen/CommandFlags.def"
// #include "llvm/CodeGen/CommandFlags.def"
#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
#include "llvm/CodeGen/LinkAllCodegenComponents.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
......@@ -48,7 +49,7 @@
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/YAMLTraits.h"
......@@ -63,7 +64,7 @@
namespace librocmlite
{
using namespace llvm;
static llvm::LLVMContext *TheContext = nullptr;
bool DisableInline = false;
......@@ -76,6 +77,7 @@ namespace librocmlite
static const std::string MArch = "amdgcn"; // AMD Graphics Core Next
static llvm::codegen::RegisterCodeGenFlags CodeGenFlags;
// ModuleRef impl
ModuleRef::ModuleRef(Module * module) : M(module) { };
......@@ -98,7 +100,7 @@ namespace librocmlite
std::string ModuleRef::to_string()
{
std::string buf;
raw_string_ostream os(buf);
llvm::raw_string_ostream os(buf);
M->print(os, nullptr);
os.flush();
return buf;
......@@ -184,7 +186,7 @@ namespace librocmlite
// each thread really ought to have its own.
LLVMContext * Context = new LLVMContext();
TheContext = Context;
// Initialize targets
// FROM OPT and LLC
......@@ -210,12 +212,12 @@ namespace librocmlite
// For codegen passes, only passes that do IR to IR transformation are
// supported.
initializeExpandMemCmpPassPass(Registry);
initializeScalarizeMaskedMemIntrinPass(Registry);
// initializeScalarizeMaskedMemIntrinPass(Registry);
initializeCodeGenPreparePass(Registry);
initializeAtomicExpandPass(Registry);
initializeRewriteSymbolsLegacyPassPass(Registry);
initializeWinEHPreparePass(Registry);
initializeDwarfEHPreparePass(Registry);
// initializeDwarfEHPreparePass(Registry);
initializeSafeStackLegacyPassPass(Registry);
initializeSjLjEHPreparePass(Registry);
initializePreISelIntrinsicLoweringLegacyPassPass(Registry);
......@@ -295,7 +297,7 @@ namespace librocmlite
{
Builder.Inliner = createAlwaysInlinerLegacyPass();
}
Builder.DisableUnitAtATime = !UnitAtATime;
// Builder.DisableUnitAtATime = !UnitAtATime;
Builder.DisableUnrollLoops = OptLevel == 0;
// This is final, unless there is a #pragma vectorize enable
......@@ -347,7 +349,7 @@ namespace librocmlite
return TheTarget->createTargetMachine(TheTriple.getTriple(),
CPUStr, FeaturesStr, Options,
getRelocModel(), getCodeModel(),
llvm::codegen::getExplicitRelocModel(), llvm::codegen::getExplicitCodeModel(),
GetCodeGenOptLevel(OptLevel));
}
......@@ -393,7 +395,7 @@ namespace librocmlite
}
M->setTargetTriple(Triple::normalize("amdgcn--amdhsa"));
M->setTargetTriple(Triple::normalize("amdgcn-amd-amdhsa"));
Triple ModuleTriple(M->getTargetTriple());
......@@ -411,7 +413,7 @@ namespace librocmlite
// Override function attributes based on CPUStr, FeaturesStr, and command line
// flags.
setFunctionAttributes(CPUStr, FeaturesStr, *M);
llvm::codegen::setFunctionAttributes(CPUStr, FeaturesStr, *M);
// Create a PassManager to hold and optimize the collection of passes we are
// about to build.
......@@ -483,7 +485,7 @@ namespace librocmlite
// --- START LLC section ---
int CompileModule(std::unique_ptr<Module> mod, raw_string_ostream &os, bool emitBRIG,
int CompileModule(std::unique_ptr<Module> mod, llvm::raw_string_ostream &os, bool emitBRIG,
int OptLevel, const char * Cpu)
{
// Load the module to be compiled...
......@@ -491,7 +493,7 @@ namespace librocmlite
Triple TheTriple;// = Triple(mod->getTargetTriple());
TheTriple = Triple(Triple::normalize("amdgcn--amdhsa"));
TheTriple = Triple(Triple::normalize("amdgcn-amd-amdhsa"));
// Get the target specific parser.
std::string Error;
......@@ -506,7 +508,8 @@ namespace librocmlite
// Package up features to be passed to target/subtarget
std::string CPUStr(Cpu);
std::string FeaturesStr = "+promote-alloca,+fp64-denormals,+flat-for-global,";
// std::string FeaturesStr = "+promote-alloca,+fp64-denormals,+flat-for-global,";
std::string FeaturesStr = "+promote-alloca,+flat-for-global,";
CodeGenOpt::Level OLvl = CodeGenOpt::Default;
switch (OptLevel)
......@@ -525,20 +528,20 @@ namespace librocmlite
break;
}
TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
TargetOptions Options = llvm::codegen::InitTargetOptionsFromCodeGenFlags(Triple());
Options.MCOptions.AsmVerbose = true;
std::unique_ptr<TargetMachine> Target(
TheTarget->createTargetMachine(TheTriple.getTriple(), CPUStr, FeaturesStr,
Options, getRelocModel(), getCodeModel(),
Options, llvm::codegen::getExplicitRelocModel(), llvm::codegen::getExplicitCodeModel(),
OLvl));
assert(Target && "Could not allocate target machine!");
assert(mod && "Should have exited if we didn't have a module!");
if (FloatABIForCalls != FloatABI::Default)
Options.FloatABIType = FloatABIForCalls;
// if (FloatABIForCalls != FloatABI::Default)
// Options.FloatABIType = FloatABIForCalls;
// Build up all of the passes that we want to do to the module.
legacy::PassManager PM;
......@@ -554,11 +557,11 @@ namespace librocmlite
// Add the target data from the target machine, if it exists, or the module./
mod->setDataLayout(Target->createDataLayout());
setFunctionAttributes(CPUStr, FeaturesStr, *mod);
llvm::codegen::setFunctionAttributes(CPUStr, FeaturesStr, *mod);
auto FileType = (emitBRIG
? TargetMachine::CGFT_ObjectFile
: TargetMachine::CGFT_AssemblyFile);
? CGFT_ObjectFile
: CGFT_AssemblyFile);
{
// new scope
......@@ -566,7 +569,8 @@ namespace librocmlite
// Ask the target to add backend passes as necessary.
bool Verify = true;
if (Target->addPassesToEmitFile(PM, BOS, FileType, Verify))
if (Target->addPassesToEmitFile(PM, BOS, nullptr, FileType, Verify, nullptr))
// if (Target->addPassesToEmitFile(PM, BOS, FileType, Verify))
{
errs() << "target does not support generation of this"
<< " file type!\n";
......@@ -668,7 +672,7 @@ extern "C" {
if (OptLevel < 0 || OptLevel > 3) return 0;
// Compile
std::string buf;
raw_string_ostream os(buf);
llvm::raw_string_ostream os(buf);
int status = CompileModule(std::move(sM), os, false, OptLevel, Cpu);
if(status) return 0;
// Write output
......@@ -686,7 +690,7 @@ extern "C" {
if (OptLevel < 0 || OptLevel > 3) return 0;
// Compile
std::string buf;
raw_string_ostream os(buf);
llvm::raw_string_ostream os(buf);
int status = CompileModule(std::move(sM), os, true, OptLevel, Cpu);
if(status) return 0;
// Write output
......
; ModuleID = 'copy_kernel_1d'
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n32"
target triple = "amdgcn--amdhsa"
target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7"
target triple = "amdgcn-amd-amdhsa"
define internal spir_func i32 @hsapy_devfn__5F__5F_main_5F__5F__2E_copy_5F_kernel_5F_1d_24_1_2E_array_28_float32_2C__20_1d_2C__20_C_29__2E_array_28_float32_2C__20_1d_2C__20_C_29_(i8** %.ret, i8* %arg.out.0, i8* %arg.out.1, i64 %arg.out.2, i64 %arg.out.3, float addrspace(4)* %arg.out.4, i64 %arg.out.5.0, i64 %arg.out.6.0, i8* %arg.inp.0, i8* %arg.inp.1, i64 %arg.inp.2, i64 %arg.inp.3, float addrspace(4)* %arg.inp.4, i64 %arg.inp.5.0, i64 %arg.inp.6.0) {
entry:
......
......@@ -51,15 +51,14 @@ std::string read_bc_from_file(const char * filename)
// the names of the bitcode files that need linking in
std::vector<std::string> _bitcodes = { \
"opencl.amdgcn.bc", \
"ocml.amdgcn.bc", \
"ockl.amdgcn.bc", \
"oclc_correctly_rounded_sqrt_off.amdgcn.bc", \
"oclc_daz_opt_off.amdgcn.bc", \
"oclc_finite_only_off.amdgcn.bc", \
"oclc_isa_version_803.amdgcn.bc", \
"oclc_unsafe_math_off.amdgcn.bc", \
"irif.amdgcn.bc"
"opencl.bc", \
"ocml.bc", \
"ockl.bc", \
"oclc_correctly_rounded_sqrt_off.bc", \
"oclc_daz_opt_off.bc", \
"oclc_finite_only_off.bc", \
"oclc_isa_version_906.bc", \
"oclc_unsafe_math_off.bc"
};
......@@ -103,7 +102,7 @@ TEST(TEST_BASE, test_parse_ir_module)
// Check the module BC parse works cleanly and can then be destroyed.
TEST(TEST_BASE, test_parse_bc_module)
{
std::string bc = read_bc_from_file("opencl.amdgcn.bc");
std::string bc = read_bc_from_file("opencl.bc");
ModuleRef* theRef = ROC_ParseBitcode(bc.c_str(), bc.size());
ROC_ModuleDestroy(theRef);
}
......@@ -163,7 +162,7 @@ TEST(TEST_BASE, test_optimize_module)
}
// run an optimisation pass over the module
ret = ROC_ModuleOptimize(dst, 3, 0, 1, "fiji");
ret = ROC_ModuleOptimize(dst, 0, 0, 1, "gfx906");
EXPECT_TRUE(ret == 1);
ROC_ModuleDestroy(dst);
......@@ -192,10 +191,10 @@ TEST(TEST_BASE, test_compile_module_to_HSAIL)
ROC_ModuleDestroy(bc_src);
}
const char * cpu = "fiji";
const char * cpu = "gfx906";
// run an optimisation pass over the module
ret = ROC_ModuleOptimize(dst, 3, 0, 1, cpu);
ret = ROC_ModuleOptimize(dst, 0, 0, 1, cpu);
ASSERT_TRUE(ret == 1);
char * output;
......@@ -235,10 +234,10 @@ TEST(TEST_BASE, test_compile_module_to_BRIG)
ROC_ModuleDestroy(bc_src);
}
const char * cpu = "fiji";
const char * cpu = "gfx906";
// run an optimisation pass over the module
ret = ROC_ModuleOptimize(dst, 3, 0, 1, cpu);
ret = ROC_ModuleOptimize(dst, 0, 0, 1, cpu);
ASSERT_TRUE(ret == 1);
char * output;
......@@ -259,51 +258,51 @@ TEST(TEST_BASE, test_compile_module_to_BRIG)
}
// Test many compilation calls to BRIG works
TEST(TEST_BASE, test_many_compile_module_to_BRIG)
{
const char * cpu = "fiji";
int trials = 5;
// TEST(TEST_BASE, test_many_compile_module_to_BRIG)
// {
// const char * cpu = "gfx906";
// int trials = 5;
for(int k = 0; k < trials; k++)
{
ROC_Initialize();
std::string ir = read_ir_from_file("demo_ir.ll");
ModuleRef* dst = ROC_ParseModule(ir.c_str());
// for(int k = 0; k < trials; k++)
// {
// ROC_Initialize();
// std::string ir = read_ir_from_file("demo_ir.ll");
// ModuleRef* dst = ROC_ParseModule(ir.c_str());
int ret;
// int ret;
for (auto& bitcode : _bitcodes)
{
// for (auto& bitcode : _bitcodes)
// {
std::string builtins_bc = read_bc_from_file(bitcode.c_str());
ModuleRef* bc_src = ROC_ParseBitcode(builtins_bc.c_str(),
builtins_bc.size());
// std::string builtins_bc = read_bc_from_file(bitcode.c_str());
// ModuleRef* bc_src = ROC_ParseBitcode(builtins_bc.c_str(),
// builtins_bc.size());
// link the builtins into the module
ret = ROC_ModuleLinkIn(dst, bc_src);
EXPECT_TRUE(ret != 0);
// // link the builtins into the module
// ret = ROC_ModuleLinkIn(dst, bc_src);
// EXPECT_TRUE(ret != 0);
ROC_ModuleDestroy(bc_src);
}
// ROC_ModuleDestroy(bc_src);
// }
// run an optimisation pass over the module
ret = ROC_ModuleOptimize(dst, 3, 0, 1, cpu);
ASSERT_TRUE(ret == 1);
// // run an optimisation pass over the module
// ret = ROC_ModuleOptimize(dst, 0, 0, 1, cpu);
// ASSERT_TRUE(ret == 1);
char * output;
ret = ROC_ModuleEmitBRIG(dst, 2, cpu, &output);
EXPECT_TRUE(ret > 0);
// char * output;
// ret = ROC_ModuleEmitBRIG(dst, 2, cpu, &output);
// EXPECT_TRUE(ret > 0);
char elf_string[] = "\x7f\x45\x4c\x46";
// char elf_string[] = "\x7f\x45\x4c\x46";
// check this is an ELF object
for (size_t i = 0; i < 4; i++)
{
EXPECT_TRUE(output[i]==elf_string[i]);
}
// // check this is an ELF object
// for (size_t i = 0; i < 4; i++)
// {
// EXPECT_TRUE(output[i]==elf_string[i]);
// }
free(output);
// free(output);
ROC_ModuleDestroy(dst);
}
}
// ROC_ModuleDestroy(dst);
// }
// }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment