Skip to content

Commit

Permalink
Merge branch 'upc-ir'
Browse files Browse the repository at this point in the history
  • Loading branch information
swatanabe committed Dec 23, 2014
2 parents 7a98efd + a20c098 commit 8e8d628
Show file tree
Hide file tree
Showing 25 changed files with 2,124 additions and 54 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ set(UPC_PTS "packed" CACHE STRING "UPC shared pointer representation (packed|str
set(UPC_PACKED_BITS "20,10,34" CACHE STRING "UPC shared pointer bits per field (phase,thread,addr) default 20,10,34")
set(UPC_PTS_VADDR_ORDER "first" CACHE STRING "UPC shared pointer field order default first")

# UPC IR Remote Pointer Representation
set(UPC_IR_REMOTE_POINTER_BITS "20,44" CACHE STRING "UPC remote pointer bits per field (thread,addr) default 20,44")
string(REPLACE "," ";" UPC_IR_RP_LIST ${UPC_IR_REMOTE_POINTER_BITS})
list(GET UPC_IR_RP_LIST 0 UPC_RP_THREAD)
list(GET UPC_IR_RP_LIST 1 UPC_RP_ADDR)
math(EXPR UPC_RP_SIZE "${UPC_RP_THREAD} + ${UPC_RP_ADDR}")
if (NOT UPC_RP_SIZE EQUAL 64)
message(FATAL_ERROR "UPC Remote Pointer fields must add to 64 bits (UPC_IR_REMOTE_POINTER_BITS).")
endif()
set(UPC_IR_RP_THREAD ${UPC_RP_THREAD})
set(UPC_IR_RP_ADDR ${UPC_RP_ADDR})
# UPC IR Remote Pointer address space
set(UPC_IR_RP_ADDRSPACE "16" CACHE STRING "UPC remote pointer address space")
set(UPC_IR_RP_ADDRSPACE ${UPC_IR_RP_ADDRSPACE})

# Check for Portals4 and SLURM libraries if necessary
set(LIBUPC_RUNTIME_MODEL smp CACHE STRING "specify the runtime implementation model for UPC, where MODEL may be: '
smp' (Symmetric Multiprocessing) or 'portals4' (Infiniband with Portals4 library)")
Expand Down
1 change: 1 addition & 0 deletions include/clang/Basic/LangOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ LANGOPT(UPCPtsRep, 1, 1, "UPC pointer representation (1 packed, 0 struct)")
LANGOPT(UPCVaddrFirst, 1, 0, "UPC pointer field order")
LANGOPT(UPCInlineLib, 1, 0, "inline the UPC runtime")
LANGOPT(UPCPreInclude, 1, 0, "pre-include UPC runtime header files")
LANGOPT(UPCGenIr, 1, 0, "generate LLVM IR for UPC shared accesses")
LANGOPT(UPCTLDEnable, 1, 0, "enable support for Thread Local Data")

LANGOPT(MRTD , 1, 0, "-mrtd calling convention")
Expand Down
9 changes: 9 additions & 0 deletions include/clang/Config/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
/* the field order */
#cmakedefine UPC_PTS_VADDR_ORDER "${UPC_PTS_VADDR_ORDER}"

/* UPC Remote Pointer thread field size */
#cmakedefine UPC_IR_RP_THREAD ${UPC_IR_RP_THREAD}

/* UPC Remote Pointer address field size */
#cmakedefine UPC_IR_RP_ADDR ${UPC_IR_RP_ADDR}

/* UPC Remote Pointer address space */
#cmakedefine UPC_IR_RP_ADDRSPACE ${UPC_IR_RP_ADDRSPACE}

/* UPC runtime NUMA enable. */
#cmakedefine LIBUPC_ENABLE_NUMA 1

Expand Down
11 changes: 10 additions & 1 deletion include/clang/Config/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@
/* the number of bits in each field. */
#undef UPC_PACKED_BITS

/* the field order */
/* the field order. */
#undef UPC_PTS_VADDR_ORDER

/* UPC Remote Pointer thread field size. */
#undef UPC_IR_RP_THREAD

/* UPC Remote Pointer address field size. */
#undef UPC_IR_RP_ADDR

/* UPC Remote Pointer address space. */
#undef UPC_IR_RP_ADDRSPACE

/* Define to 1 if UPC runtime NUMA is supported. */
#undef LIBUPC_ENABLE_NUMA

Expand Down
4 changes: 4 additions & 0 deletions include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,10 @@ def fno_upc_pre_include : Flag<["-"], "fno-upc-pre-include">, Group<f_Group>, Fl
def fupc_debug : Flag<["-"], "fupc-debug">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Generate UPC runtime calls that include debugging information">;
def fno_upc_debug : Flag<["-"], "fno-upc-debug">, Group<f_Group>;
def fupc_ir : Flag<["-"], "fupc-ir">,
Group<f_Group>, Flags<[CC1Option]>;
def fno_upc_ir : Flag<["-"], "fno-upc-ir">,
Group<f_Group>, Flags<[CC1Option]>;
def foperator_arrow_depth_EQ : Joined<["-"], "foperator-arrow-depth=">,
Group<f_Group>;
def ftest_coverage : Flag<["-"], "ftest-coverage">, Group<f_Group>;
Expand Down
17 changes: 17 additions & 0 deletions lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/UPC.h"
using namespace clang;
using namespace llvm;

Expand Down Expand Up @@ -222,6 +223,11 @@ static void addDataFlowSanitizerPass(const PassManagerBuilder &Builder,
PM.add(createDataFlowSanitizerPass(CGOpts.SanitizerBlacklistFile));
}

static void addLowerUPCPointersPass(const PassManagerBuilder &Builder,
PassManagerBase &PM) {
PM.add(llvm::createLowerUPCPointersPass());
}

void EmitAssemblyHelper::CreatePasses(TargetMachine *TM) {
unsigned OptLevel = CodeGenOpts.OptimizationLevel;
CodeGenOptions::InliningMethod Inlining = CodeGenOpts.getInlining();
Expand Down Expand Up @@ -536,6 +542,17 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action,
CodeGenOpts.OptimizationLevel > 0)
PM->add(createObjCARCContractPass());

// Add LLVM UPC lowering pass unless we're generating LLVM output
if (LangOpts.UPCGenIr) {
switch(Action) {
case Backend_EmitLL:
case Backend_EmitBC:
break;
default:
PM->add(llvm::createLowerUPCPointersPass());
}
}

if (TM->addPassesToEmitFile(*PM, OS, CGFT,
/*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
Diags.Report(diag::err_fe_unable_to_interface_with_target);
Expand Down
42 changes: 41 additions & 1 deletion lib/CodeGen/CGExprUPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "clang/Basic/TargetInfo.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/ADT/SmallVector.h"
#include "clang/Config/config.h" // for UPC_IR_RP_THREAD/ADDR
using namespace clang;
using namespace CodeGen;

Expand Down Expand Up @@ -180,11 +181,41 @@ llvm::Value *CodeGenFunction::EmitUPCLoad(llvm::Value *Addr,
return EmitFromMemory(EmitUPCLoad(Addr, isStrict, DestLTy, Align, Loc), Ty);
}

static const int UPCAddrSpace = UPC_IR_RP_ADDRSPACE;

static llvm::Value *ConvertPTStoLLVMPtr(CodeGenFunction& CGF,
llvm::Value *Ptr, llvm::Type *LTy) {
llvm::Value *Addr = CGF.EmitUPCPointerGetAddr(Ptr);
llvm::Value *Thread = CGF.EmitUPCPointerGetThread(Ptr);

const LangOptions& LangOpts = CGF.getContext().getLangOpts();
if(!LangOpts.UPCPtsRep) {
llvm::Value *SectionStart = CGF.CGM.getModule().getOrInsertGlobal("__upc_shared_start", CGF.Int8Ty);
llvm::Value *StartInt = CGF.Builder.CreatePtrToInt(SectionStart, CGF.PtrDiffTy, "sect.cast");
Addr = CGF.Builder.CreateSub(Addr, StartInt, "addr.sub");
}

llvm::Value *IntVal = CGF.Builder.CreateOr(Thread, CGF.Builder.CreateShl(Addr, UPC_IR_RP_THREAD));

llvm::Type *LLPtsTy = LTy->getPointerTo(UPCAddrSpace);
return CGF.Builder.CreateIntToPtr(IntVal, LLPtsTy);
}

llvm::Value *CodeGenFunction::EmitUPCLoad(llvm::Value *Addr,
bool isStrict,
llvm::Type *LTy,
CharUnits Align,
SourceLocation Loc) {
const LangOptions& Opts = getContext().getLangOpts();
if (Opts.UPCGenIr) {
llvm::Value *InternalAddr = ConvertPTStoLLVMPtr(*this, Addr, LTy);
llvm::LoadInst * Result = Builder.CreateLoad(InternalAddr);
if(isStrict) {
Result->setOrdering(llvm::SequentiallyConsistent);
}
Result->setAlignment(Align.getQuantity());
return Result;
}
const ASTContext& Context = getContext();
const llvm::DataLayout &Target = CGM.getDataLayout();
uint64_t Size = Target.getTypeSizeInBits(LTy);
Expand Down Expand Up @@ -251,7 +282,16 @@ void CodeGenFunction::EmitUPCStore(llvm::Value *Value,
bool isStrict,
CharUnits Align,
SourceLocation Loc) {

const LangOptions& Opts = getContext().getLangOpts();
if (Opts.UPCGenIr) {
llvm::Value *InternalAddr = ConvertPTStoLLVMPtr(*this, Addr, Value->getType());
llvm::StoreInst * Result = Builder.CreateStore(Value, InternalAddr);
if(isStrict) {
Result->setOrdering(llvm::SequentiallyConsistent);
}
Result->setAlignment(Align.getQuantity());
return;
}
const ASTContext& Context = getContext();
const llvm::DataLayout &Target = CGM.getDataLayout();
uint64_t Size = Target.getTypeSizeInBits(Value->getType());
Expand Down
1 change: 1 addition & 0 deletions lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
ipo
linker
vectorize
upc
)

add_clang_library(clangCodeGen
Expand Down
2 changes: 2 additions & 0 deletions lib/Driver/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3525,6 +3525,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_fno_upc_inline_lib);
Args.AddAllArgs(CmdArgs, options::OPT_fupc_pre_include,
options::OPT_fno_upc_pre_include);
Args.AddAllArgs(CmdArgs, options::OPT_fupc_ir,
options::OPT_fno_upc_ir);

if (Args.hasFlag(options::OPT_fupc_debug,
options::OPT_fno_upc_debug, false))
Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Args.hasFlag(OPT_fupc_inline_lib, OPT_fno_upc_inline_lib, false)))
Opts.UPCInlineLib = true;

if (Opts.UPC && Args.hasArg(OPT_fupc_ir))
Opts.UPCGenIr = true;

// This is the __NO_INLINE__ define, which just depends on things like the
// optimization level and -fno-inline, not actually whether the backend has
// inlining enabled.
Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
if (LangOpts.UPCInlineLib) {
Builder.defineMacro("__UPC_INLINE_LIB__", "1");
}
if (LangOpts.UPCGenIr) {
Builder.defineMacro("__UPC_SHARED_IR__", "1");
}
}

// Not "standard" per se, but available even with the -undef flag.
Expand Down
3 changes: 3 additions & 0 deletions runtime/libupc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ endif()
elseif(LIBUPC_RUNTIME_MODEL STREQUAL portals4)
set(LIBUPC_SOURCES
portals4/gupcr_access.c
portals4/gupcr_llvm_access.c
portals4/gupcr_addr.c
portals4/gupcr_alloc.upc
portals4/gupcr_atomic_sup.c
Expand Down Expand Up @@ -415,7 +416,9 @@ elseif(LIBUPC_RUNTIME_MODEL STREQUAL portals4)

set(LIBUPC_SOURCES_INLINE
${PROJECT_SOURCE_DIR}/portals4/gupcr_access.c
${PROJECT_SOURCE_DIR}/portals4/gupcr_llvm_access.c
${PROJECT_SOURCE_DIR}/portals4/gupcr_access.h
${PROJECT_SOURCE_DIR}/portals4/gupcr_llvm_access.h
${PROJECT_SOURCE_DIR}/portals4/gupcr_config.h
${PROJECT_SOURCE_DIR}/portals4/gupcr_defs.h
${PROJECT_SOURCE_DIR}/portals4/gupcr_gmem.h
Expand Down
3 changes: 1 addition & 2 deletions runtime/libupc/autoconf/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2112,8 +2112,7 @@ if test "$upc_runtime_model" = "smp"; then
upc_numa=yes ;;
no)
upc_numa=no ;;
*)
AC_MSG_ERROR([--enable-upc-numa accepts only yes or no])
*) AC_MSG_ERROR([--enable-upc-numa accepts only yes or no])
esac
],
[
Expand Down
Loading

0 comments on commit 8e8d628

Please sign in to comment.