mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-03 14:31:10 +00:00
Fix for PR19099 - NVPTX produces invalid symbol names.
This is a more thorough fix for the issue than r203483. An IR pass will run before NVPTX codegen to make sure there are no invalid symbol names that can't be consumed by the ptxas assembler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205212 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
93b3fcae28
commit
416a0e993f
@ -23,6 +23,7 @@ set(NVPTXCodeGen_sources
|
||||
NVPTXUtilities.cpp
|
||||
NVVMReflect.cpp
|
||||
NVPTXGenericToNVVM.cpp
|
||||
NVPTXAssignValidGlobalNames.cpp
|
||||
NVPTXPrologEpilogPass.cpp
|
||||
NVPTXMCExpr.cpp
|
||||
)
|
||||
|
@ -61,6 +61,7 @@ inline static const char *NVPTXCondCodeToString(NVPTXCC::CondCodes CC) {
|
||||
|
||||
FunctionPass *
|
||||
createNVPTXISelDag(NVPTXTargetMachine &TM, llvm::CodeGenOpt::Level OptLevel);
|
||||
ModulePass *createNVPTXAssignValidGlobalNamesPass();
|
||||
ModulePass *createGenericToNVVMPass();
|
||||
ModulePass *createNVVMReflectPass();
|
||||
ModulePass *createNVVMReflectPass(const StringMap<int>& Mapping);
|
||||
|
84
lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
Normal file
84
lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
//===-- NVPTXAssignValidGlobalNames.cpp - Assign valid names to globals ---===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Clean up the names of global variables in the module to not contain symbols
|
||||
// that are invalid in PTX.
|
||||
//
|
||||
// Currently NVPTX, like other backends, relies on generic symbol name
|
||||
// sanitizing done by MC. However, the ptxas assembler is more stringent and
|
||||
// disallows some additional characters in symbol names. This pass makes sure
|
||||
// such names do not reach MC at all.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "NVPTX.h"
|
||||
#include "llvm/IR/GlobalVariable.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/PassManager.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <string>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
/// \brief NVPTXAssignValidGlobalNames
|
||||
class NVPTXAssignValidGlobalNames : public ModulePass {
|
||||
public:
|
||||
static char ID;
|
||||
NVPTXAssignValidGlobalNames() : ModulePass(ID) {}
|
||||
|
||||
virtual bool runOnModule(Module &M);
|
||||
|
||||
/// \brief Clean up the name to remove symbols invalid in PTX.
|
||||
std::string cleanUpName(StringRef Name);
|
||||
};
|
||||
}
|
||||
|
||||
char NVPTXAssignValidGlobalNames::ID = 0;
|
||||
|
||||
namespace llvm {
|
||||
void initializeNVPTXAssignValidGlobalNamesPass(PassRegistry &);
|
||||
}
|
||||
|
||||
INITIALIZE_PASS(NVPTXAssignValidGlobalNames, "nvptx-assign-valid-global-names",
|
||||
"Assign valid PTX names to globals", false, false)
|
||||
|
||||
bool NVPTXAssignValidGlobalNames::runOnModule(Module &M) {
|
||||
for (GlobalVariable &GV : M.globals()) {
|
||||
// We are only allowed to rename local symbols.
|
||||
if (GV.hasLocalLinkage()) {
|
||||
// setName doesn't do extra work if the name does not change.
|
||||
// Note: this does not create collisions - if setName is asked to set the
|
||||
// name to something that already exists, it adds a proper postfix to
|
||||
// avoid collisions.
|
||||
GV.setName(cleanUpName(GV.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string NVPTXAssignValidGlobalNames::cleanUpName(StringRef Name) {
|
||||
std::string ValidName;
|
||||
raw_string_ostream ValidNameStream(ValidName);
|
||||
for (unsigned I = 0, E = Name.size(); I != E; ++I) {
|
||||
char C = Name[I];
|
||||
if (C == '.' || C == '@') {
|
||||
ValidNameStream << "_$_";
|
||||
} else {
|
||||
ValidNameStream << C;
|
||||
}
|
||||
}
|
||||
|
||||
return ValidNameStream.str();
|
||||
}
|
||||
|
||||
ModulePass *llvm::createNVPTXAssignValidGlobalNamesPass() {
|
||||
return new NVPTXAssignValidGlobalNames();
|
||||
}
|
@ -49,6 +49,7 @@ using namespace llvm;
|
||||
namespace llvm {
|
||||
void initializeNVVMReflectPass(PassRegistry&);
|
||||
void initializeGenericToNVVMPass(PassRegistry&);
|
||||
void initializeNVPTXAssignValidGlobalNamesPass(PassRegistry&);
|
||||
}
|
||||
|
||||
extern "C" void LLVMInitializeNVPTXTarget() {
|
||||
@ -60,6 +61,7 @@ extern "C" void LLVMInitializeNVPTXTarget() {
|
||||
// but it's very NVPTX-specific.
|
||||
initializeNVVMReflectPass(*PassRegistry::getPassRegistry());
|
||||
initializeGenericToNVVMPass(*PassRegistry::getPassRegistry());
|
||||
initializeNVPTXAssignValidGlobalNamesPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
static std::string computeDataLayout(const NVPTXSubtarget &ST) {
|
||||
@ -139,6 +141,7 @@ void NVPTXPassConfig::addIRPasses() {
|
||||
disablePass(&TailDuplicateID);
|
||||
|
||||
TargetPassConfig::addIRPasses();
|
||||
addPass(createNVPTXAssignValidGlobalNamesPass());
|
||||
addPass(createGenericToNVVMPass());
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,31 @@
|
||||
; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s --check-prefix=PTX32
|
||||
; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s --check-prefix=PTX64
|
||||
|
||||
@.str = private unnamed_addr constant [6 x i8] c"%d %f\00", align 1
|
||||
@.str.again = private unnamed_addr constant [6 x i8] c"%d %f\00", align 1
|
||||
; Verify that the NVPTX target removes invalid symbol names prior to emitting
|
||||
; PTX.
|
||||
|
||||
; PTX32-NOT: .str
|
||||
; PTX64-NOT: .str
|
||||
|
||||
; PTX32-DAG: _$_str1
|
||||
; PTX32-DAG: _$_str
|
||||
|
||||
; PTX64-DAG: _$_str1
|
||||
; PTX64-DAG: _$_str
|
||||
|
||||
target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
|
||||
target triple = "nvptx64-unknown-unknown"
|
||||
|
||||
|
||||
@.str = private unnamed_addr constant [13 x i8] c"%d %f %c %d\0A\00", align 1
|
||||
@_$_str = private unnamed_addr constant [13 x i8] c"%d %f %c %d\0A\00", align 1
|
||||
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define void @foo(i32 %a, float %b, i8 signext %c, i32 %e) {
|
||||
entry:
|
||||
%call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([13 x i8]* @.str, i32 0, i32 0))
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i32 @printf(i8*, ...)
|
||||
|
Loading…
x
Reference in New Issue
Block a user