651 changes: 325 additions & 326 deletions llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions llvm/test/CodeGen/AMDGPU/opencl-printf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
; FUNC-LABEL: @test_kernel(
; R600-LABEL: entry
; R600-NOT: call i8 addrspace(1)* @__printf_alloc
; R600: call i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str, i32 0, i32 0), i8 addrspace(5)* %arraydecay, i32 %n)
; R600: call i32 (i8 addrspace(4)*, ...) @printf(i8 addrspace(4)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(4)* @.str, i32 0, i32 0), i8 addrspace(5)* %arraydecay, i32 %n)
; GCN-LABEL: entry
; GCN: call i8 addrspace(1)* @__printf_alloc
; GCN-LABEL: entry.split
Expand All @@ -22,14 +22,14 @@
; GCN: %PrintBuffPtrCast1 = bitcast i8 addrspace(1)* %PrintBuffNextPtr to i32 addrspace(1)*
; GCN: store i32 %n, i32 addrspace(1)* %PrintBuffPtrCast1

@.str = private unnamed_addr addrspace(2) constant [6 x i8] c"%s:%d\00", align 1
@.str = private unnamed_addr addrspace(4) constant [6 x i8] c"%s:%d\00", align 1

define amdgpu_kernel void @test_kernel(i32 %n) {
entry:
%str = alloca [9 x i8], align 1, addrspace(5)
%arraydecay = getelementptr inbounds [9 x i8], [9 x i8] addrspace(5)* %str, i32 0, i32 0
%call1 = call i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str, i32 0, i32 0), i8 addrspace(5)* %arraydecay, i32 %n)
%call1 = call i32 (i8 addrspace(4)*, ...) @printf(i8 addrspace(4)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(4)* @.str, i32 0, i32 0), i8 addrspace(5)* %arraydecay, i32 %n)
ret void
}

declare i32 @printf(i8 addrspace(2)*, ...)
declare i32 @printf(i8 addrspace(4)*, ...)
39 changes: 39 additions & 0 deletions llvm/unittests/Support/ProgramTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,45 @@ TEST_F(ProgramEnvTest, TestExecuteAndWaitTimeout) {
ASSERT_EQ(-2, RetCode);
}

TEST_F(ProgramEnvTest, TestExecuteNoWaitTimeoutPolling) {
using namespace llvm::sys;

if (getenv("LLVM_PROGRAM_TEST_TIMEOUT")) {
sleep_for(/*seconds*/ 5);
exit(0);
}

std::string Executable =
sys::fs::getMainExecutable(TestMainArgv0, &ProgramTestStringArg1);
StringRef argv[] = {
Executable,
"--gtest_filter=ProgramEnvTest.TestExecuteNoWaitTimeoutPolling"};

// Add LLVM_PROGRAM_TEST_TIMEOUT to the environment of the child.
addEnvVar("LLVM_PROGRAM_TEST_TIMEOUT=1");

std::string Error;
bool ExecutionFailed;
ProcessInfo PI0 = ExecuteNoWait(Executable, argv, getEnviron(),
/*Redirects=*/{}, /*MemoryLimit=*/0, &Error,
&ExecutionFailed);
ASSERT_FALSE(ExecutionFailed) << Error;
ASSERT_NE(PI0.Pid, ProcessInfo::InvalidPid) << "Invalid process id";

// Check that we don't kill the process with a non-0 SecondsToWait if Polling.
unsigned LoopCount = 0;
ProcessInfo WaitResult;
do {
++LoopCount;
WaitResult = llvm::sys::Wait(PI0, /*SecondsToWait=*/1, &Error,
/*ProcStats=*/nullptr,
/*Polling=*/true);
ASSERT_TRUE(Error.empty()) << Error;
} while (WaitResult.Pid != PI0.Pid);

ASSERT_GT(LoopCount, 1u) << "LoopCount should be >1";
}

TEST(ProgramTest, TestExecuteNegative) {
std::string Executable = "i_dont_exist";
StringRef argv[] = {Executable};
Expand Down