Revision c3861f5c7371fea2fc5d20404a7f77c927bbd61b authored by Shuhei Kadowaki on 14 August 2021, 12:49:21 UTC, committed by Shuhei Kadowaki on 23 August 2021, 15:09:13 UTC
Built on top of #41882, this PR sorts out the constant-prop' interface yet more, particularly generalizes `force_const_prop` to `const_prop_config` so that it can turn on and off each heuristic. The main motivation here is, in #41882, we want to force const-prop' on `setproperty` even when its return type is already `Const` for the sake of succeeding inlining, by skipping all the `const_prop_xxx_heuristic` checks. But I still found we want to apply `const_prop_entry_heuristic` to `getproperty`, because if we already know very accurate result for a `getproperty` call, usually there is really no motivation for constant-prop', e.g.: ```julia struct FZero end Base.getproperty(::FZero, ::Symbol) = 0.0 getproperty(FZero(), :val) # const-prop' doesn't need to happen here ``` Now `force_const_prop(...) -> force::Bool` is refactored to `const_prop_config(...) -> config::UInt8`, which can turn on and off each heuristic based on the value of `config`. I also included another refactoring that inlines `const_prop_rettype_heuristic` into `const_prop_argument_heuristic`, because they really seem tightly coupled.
1 parent e1e4986
llvmcalltest.cpp
// This file is a part of Julia. License is MIT: https://julialang.org/license
#include "llvm-version.h"
#include "support/platform.h"
#include "support/dtypes.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/IRBuilder.h"
#include <llvm/Support/raw_ostream.h>
#include "julia.h"
#include "codegen_shared.h"
using namespace llvm;
extern "C" {
JL_DLLEXPORT const char *MakeIdentityFunction(jl_value_t* jl_AnyTy) {
LLVMContext Ctx;
PointerType *AnyTy = PointerType::get(StructType::get(Ctx), 0);
// FIXME: get AnyTy via jl_type_to_llvm(Ctx, jl_AnyTy)
Type *TrackedTy = PointerType::get(AnyTy->getElementType(), AddressSpace::Tracked);
Module *M = new llvm::Module("shadow", Ctx);
Function *F = Function::Create(
FunctionType::get(
TrackedTy, {TrackedTy}, false),
llvm::GlobalValue::ExternalLinkage,
"identity",
M
);
IRBuilder<> Builder(BasicBlock::Create(Ctx, "top", F));
Builder.CreateRet(&*F->arg_begin());
std::string buf;
raw_string_ostream os(buf);
M->print(os, NULL);
os.flush();
return strdup(buf.c_str());
}
JL_DLLEXPORT const char *MakeLoadGlobalFunction() {
LLVMContext Ctx;
auto M = new Module("shadow", Ctx);
auto intType = Type::getInt32Ty(Ctx);
auto G = new GlobalVariable(
*M,
intType,
true,
GlobalValue::InternalLinkage,
Constant::getNullValue(intType),
"test_global_var");
auto resultType = Type::getInt64Ty(Ctx);
auto F = Function::Create(
FunctionType::get(resultType, {}, false),
GlobalValue::ExternalLinkage,
"load_global_var",
M);
IRBuilder<> Builder(BasicBlock::Create(Ctx, "top", F));
Builder.CreateRet(Builder.CreatePtrToInt(G, resultType));
std::string buf;
raw_string_ostream os(buf);
M->print(os, NULL);
os.flush();
return strdup(buf.c_str());
}
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...